Re: [R] Command line arguments with source() - Windows OS

From: Brigid Mooney <bkmooney_at_gmail.com>
Date: Mon, 17 Nov 2008 09:14:16 -0500

Is there a better command to use rather than source which would take command arguments?

I ask because I currently have 6 parameters, will likely have additional paramaters later, and would like to be able to have default values for each, if I do not specify new values.

Thanks so much!

On Mon, Nov 17, 2008 at 9:06 AM, Duncan Murdoch <murdoch_at_stats.uwo.ca>wrote:

> Brigid Mooney wrote:
>
>> Hi Everyone,
>>
>> I am pretty new to R and so far have mostly been using R interactively
>> through the Windows console.
>>
>> I'm starting to write some scripts, and have been executing them using the
>> source() command, i.e. source(myRfile.R).
>>
>> My questions is how can I pass command line arguments to R. My file
>> "myRfile.R" has some global variables which I would like to be able to set
>> at run-time, without having to go in and edit the text of the file each
>> time
>> I want to run it.
>>
>> I can't seem to find much information on this topic for Windows and using
>> it
>> with the console - so any help would be greatly appreciated.
>>
>
> This is the same on all platforms, Windows isn't special.
>
> When you use source(), any variables currently defined in the R session
> will be visible to your script. There is no "command line" needed, because
> you're executing the R code in the same session.
>
> So you could do this:
>
> paramValue <- 10
> source("myRfile.R")
>
> paramValue <- 15
> source("myRfile.R")
>
> The quotes are necessary, because source(myRfile.R) would go looking for a
> variable named myRfile.R, rather than using "myRfile.R" as the filename.
>
> Duncan Murdoch
>
>

        [[alternative HTML version deleted]]



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. Received on Mon 17 Nov 2008 - 14:19:10 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 17 Nov 2008 - 14:30:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive