I am trying to execute all tabs in a project. The project and the execute.R tab are in a parent folder, and all tabs are in child folders which contain many folders and the tab_n.R.
How could I fix the code so that I could include all source(…) commands and run all tab_n.R in different folders?
I’m using mplusAutomation so I need to have all tabs in different folders. They must operate with the folders in the child folder.
Thanks in advance!
I tried using
source("child folder/tab_n.R", chdir = T)
but the error is
Error in file(file, ifelse(append, "a", "w")) : parent folder
cannot open the connection
In addition: Warning message:
In file(file, ifelse(append, "a", "w")) :
cannot open file 'child folder/grand child folder/Data.dat': No such file or directory.
It seems that the command is trying to open the first object in the child folder, and the .dat file in it, even though I asked it to open the tab_n.R in the child folder.
I also tried
## finds all .R and .r files within a folder and sources them
sourceFolder <- function(folder, recursive = FALSE, ...)
{
files <- list.files(folder, pattern = "[.][rR]$",
full.names = TRUE, recursive = recursive)
if (!length(files))
stop(simpleError(sprintf('No R files in folder "%s"', folder)))
src <- invisible(lapply(files, source, ...))
message(sprintf('%s files sourced from folder "%s"', length(src), folder))
}
sourceFolder("child folder", recursive = TRUE)
but it gives the same error.
I also tried
system("child folder/tab_n.R", intern = TRUE)
but with no success.
Reeta is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.