# NOT RUN {
if( !interactive() )
thisfile()
# using in terminal ( with pipe() )
# open a temp file
tf <- tempfile(fileext = '.R')
# call to write to temp file
f <- 'cat(whereami::thisfile(), "\n", sep = "")'
# write to the file
cat(f,file = tf)
# create an R call to terminal
fcmd <- sprintf('"%s" --slave --vanilla --no-save -f %s',R.home('bin/R'),tf)
# run the call
p <- pipe(fcmd)
# read the output
readLines(p)
# cleanup
close(p)
unlink(tf)
# }
Run the code above in your browser using DataCamp Workspace