Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the file name of the R script currently being executed (for easy automatic email of results) [duplicate]

Tags:

r

I am writing an R script in Rstudio, and I would like some way to get the name of the file the code is written in. The reason why I want to do this is I want a piece of code I can stick at the bottom of all my scripts so that my results are automatically emailed to me using the sendmailR package.

I'd like my attachment name to have the structure filename_date where filename is the name of the file being executed and date is the time of the execution. Is there a way of doing this, or will I have to type out the name of the file by hand every time I run a new script.

A similar question was asked here, but because the use was different the workaround solution never provided an answer. I actually don't need the location, just the filename and I think this is what should make it doable (but maybe not)

Find location of current .R file

Rscript: Determine path of the executing script (asks basically the same question but wants the whole path, no accepted answer)

like image 465
WetlabStudent Avatar asked Aug 16 '13 02:08

WetlabStudent


1 Answers

Another workaround would be to source your scripts from a master script,

script <- "mycode.R"
source(script)
...
doOtherThings(script)

and you could loop through all scripts you have, send emails about them, whatever.

like image 148
Remko Duursma Avatar answered Oct 13 '22 16:10

Remko Duursma