[R] About source()

Li SUN vraifreud.test at gmail.com
Wed Jan 4 23:49:21 CET 2012


Thanks, guys!

I am using Rscript at the moment and will definitely try littler.

Li Sun



2012/1/4 Rainer M Krug <r.m.krug at gmail.com>:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 04/01/12 10:39, Uwe Ligges wrote:
>>
>>
>> On 03.01.2012 21:22, Li SUN wrote:
>>> Thanks, Rolf, Justin and Uwe!
>>>
>>> Actually I wanted to run .R file as a script, just like what
>>> people do for bash scripts or python scripts. It seems to me that
>>> adding "#!/usr/bin/R -f" at the first line is what I need. Is
>>> this true?
>>
>>
>> Perhaps even "Rscript" rather than "R".
>
> And there is also littler from Dirk Eddelbüttel:
>
> http://dirk.eddelbuettel.com/code/littler.html
>
> - From the description: "littler provides hash-bang (i.e. script
> starting with #!/some/path) capability for GNU R, as well as simple
> command-line and piping use."
>
> Similar to Rscript, but with some differences.
>
> I used both, and in most cases they are equivalent.
>
>
> Rainer
>
>
>>
>> Uwe Ligges
>>
>>> Li Sun
>>>
>>>
>>> 2012/1/2 Rolf Turner<rolf.turner at xtra.co.nz>:
>>>> On 03/01/12 17:02, Li SUN wrote:
>>>>>
>>>>> Hello,
>>>>>
>>>>> I am a beginner to the R language and find it fantastic and
>>>>> well-designed, quite different from other programming
>>>>> languages.
>>>>
>>>> What a refreshingly sensible attitude!!! :-)
>>>>
>>>>> This is the first time I post on the r-help mailing list.
>>>>>
>>>>> In invoking the function source(filename), it seems that the
>>>>> filename has to exist in the current working directory,
>>>>> otherwise it has to be specified in full path. So is there
>>>>> any mechanism(such as environment variable) to specify an
>>>>> additional directory of .R files that source() could search
>>>>> in?
>>>>
>>>>
>>>> I'm no expert on this, and others may correct me, but
>>>>
>>>> (1) I don't believe any such mechanism exists.
>>>>
>>>> (2) It's probably not a good idea, even if such a mechanism
>>>> were to exist.  Directories have a tree structure, rather than
>>>> being linearly ordered in the way that data bases on your R
>>>> search path are ordered.
>>>>
>>>> I believe you would run all sorts of risks of confusion and of
>>>> getting the wrong file were you to invoke such a mechanism.
>>>>
>>>> It is ``good practice'' to have separate directories
>>>> associated with different projects and to situate all files,
>>>> that you might wish to source in respect of a given project, in
>>>> the directory associated with that project.
>>>>
>>>> I know that this is an irritating sort of response --- ``No,
>>>> you can't do that, and you shouldn't do it anyway!'' --- but I
>>>> sincerely believe this to be true.
>>>>
>>>> That being said, I also believe that you could program up such
>>>> a mechanism yourself. I.e. build a function "source2()" which
>>>> would have a "hard coded" list of directories to search, and
>>>> would make use of the "try()" function.
>>>>
>>>> Might be a good exercise for you, given that you are starting
>>>> out in R and looking to upgrade your skills! :-)
>>>>
>>>> cheers,
>>>>
>>>> Rolf Turner
>>>>
>>>>
>>>
>>> ______________________________________________
>>> 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.
>>
>> ______________________________________________ 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.
>
>
> - --
> Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
> Biology, UCT), Dipl. Phys. (Germany)
>
> Centre of Excellence for Invasion Biology
> Stellenbosch University
> South Africa
>
> Tel :       +33 - (0)9 53 10 27 44
> Cell:       +33 - (0)6 85 62 59 98
> Fax :       +33 - (0)9 58 10 27 44
>
> Fax (D):    +49 - (0)3 21 21 25 22 44
>
> email:      Rainer at krugs.de
>
> Skype:      RMkrug
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.11 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk8EIs4ACgkQoYgNqgF2egpF+QCeObN8q+U6HHlM/Tsls/wF+VoH
> /twAn2zaTzVrCdTxvENSK2buPlFsjlnC
> =tEkV
> -----END PGP SIGNATURE-----



More information about the R-help mailing list