[R] How to get the current script file name in the script?

Gabor Grothendieck ggrothendieck at gmail.com
Tue Sep 22 17:54:11 CEST 2009


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.
>




More information about the R-help mailing list