[R] Passing aruments with source

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Wed Sep 8 13:04:40 CEST 2010


On Wed, Sep 8, 2010 at 11:29 AM, Joel <joda2457 at student.uu.se> wrote:
>
> That is true but then I (or anyone else using the script) most know exactly
> what the name in the script is to be able to set it correctly and so on.
> Therefor it would be much better to be able to just send in the value and
> let the script handle the variable setting.
>
> But thx for the answer

 Then what you really want to do is write a _function_ that takes
arguments, and not a script. Tell your users something like:

 Do 'source("foo.R")' and then call the fnord function with your data
set: fnord(x).

Your foo.R file looks like this:

 fnord =function(x){
   print(x) # etc
 }

It's even possible to save functions to .RData files and then tell
your users to attach() them, thus not putting objects in their working
spaces.

And the next step is to write a package for your function...

Barry



More information about the R-help mailing list