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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With