Skip to content
Prev 358975 / 398502 Next

path + name of the running R file

Hi Maurice,
If you have used "source" to run an R script, perhaps you could try
something like this:

get.running.file<-function(pattern="source",...) {
 file1 <- tempfile("Rrawhist")
 savehistory(file1)
 rawhist <- readLines(file1)
 unlink(file1)
 last.source<-grep(pattern,rev(rawhist),value=TRUE)[1]
 sourced.file<-unlist(strsplit(last.source,'"'))[2]
 return(sourced.file)
}

This is taken from the "history" function and tries to find the last
"source" command in the command history and extract the name of the
sourced file. It is very rough, but it does work as long as the first
argument to the "source" function is the quoted name of the sourced
file.

Jim


On Wed, Mar 2, 2016 at 6:01 PM, MAURICE Jean - externe
<jean-externe.maurice at edf.fr> wrote: