[R] get the scripname within the executed myscript.r

David Winsemius dwinsemius at comcast.net
Tue Nov 2 15:13:07 CET 2010


On Nov 2, 2010, at 5:47 AM, Žroutík wrote:

> Dear R-users!
>
> Is there a way to obtain the name of the executed myscript.r, i.e.  
> when
>
> cmd> rscript myscript.r
>
> is executed? (The name of the script in this case is "myscript.r")

commandArgs()

>
> Here is the explanation of why I would like to get that: Why: I have
> prepared a set of scripts (decompose_data.r,  
> plot_with_higher_resolution.r,
> plot_3D.r, etc.) placed in a root directory at one place. I keep  
> updated
> only one original of each. For each new dataset, I create a new  
> directory in
> my directory tree, and I copy r scripts with the same names  
> containing a
> line for executing the only one, e.g.
>
> source(file.path("w:/data & fits/root4scripts", "decompose_data.r"))
>
> This way I can execute old datasets with new/updated scripts  
> automatically
> (by executing all decompose_data.r in the directory tree), or by  
> copying new
> "links".r to the directory. A small inconvenience of this way of  
> executing
> is, that ones named, it is hard to change the name of the script.  
> Therefore
> I would like to introduce a function that reads the name of the  
> scriptname
> executed somewhere deep in my directory tree and executes the proper
> script.r in the root. If anybody read till here, please: Is there a  
> more
> convenient/straightforward way how manage more scripts through a  
> directory
> tree with datasets and keeping them altogether updated?
>
> Thanks for listening, Zroutik
>
> 	[[alternative HTML version deleted]]

-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list