Hi, Right now, I hardcode the file name in the script. But when I change the script name, I have to change the file name in the script to make sure the file name inside the script is synchronized with the script name. I am wondering if there is an automatic way to get the script file name in a script. Regards, Peng $ Rscript get_file_name.R> print('get_file_name.R')[1] "get_file_name.R">
Gabor Grothendieck
2009-Sep-22 15:54 UTC
[R] How to get the current script file name in the script?
Try this one line R script: print(sub(".*=", "", commandArgs()[4])) Also see the geopt package for fancier handling of arguments. On Tue, Sep 22, 2009 at 11:47 AM, Peng Yu <pengyu.ut at gmail.com> wrote:> Hi, > > Right now, I hardcode the file name in the script. But when I change > the script name, I have to change the file name in the script to make > sure the file name inside the script is synchronized with the script > name. I am wondering if there is an automatic way to get the script > file name in a script. > > Regards, > Peng > > $ Rscript get_file_name.R >> print('get_file_name.R') > [1] "get_file_name.R" >> > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Apparently Analagous Threads
- How to convert a string passed as an argument to a vector?
- Why this statement does not print anything in an if-statement that includes 'q()'?
- Command line option to an R script running through Rscript
- How to pop up the graphics window from Rscript?
- How to not to terminate read.table if the input file is empty?