Message-ID: <CAMkJdJgWqC+bVHiyVD2Uz6mBwnpqC7NkchU+-Mg5DJQ9DNJXMw@mail.gmail.com>
Date: 2011-08-19T08:13:00Z
From: Cormac Long
Subject: A question about using getSrcDirectory() with R/Rscript
In-Reply-To: <4E4CF3F6.8070303@statistik.tu-dortmund.de>
Dear Uwe,
Thanks for you suggestion. I should have spotted that (not thinking
about the order of commands properly). I still don't know why it failed
to work in RGui for me. It works now. I suspect it must be another
case of PEBCAK (Problem Exists Between Chair And Keyboard).
Best wishes,
Cormac.
2011/8/18 Uwe Ligges <ligges at statistik.tu-dortmund.de>:
> Works for me in R-patched:
>
> I guess your problem is that you have to set the options() before
> source()ing.
>
> Best,
> Uwe Ligges
>
>
>
>
> On 17.08.2011 10:31, Cormac Long wrote:
>>
>> Good morning R-help,
>>
>> I have an idiot question: I would like to use getSrcDirectory()
>> and friends to allow me to identify where an R file has been
>> called from when invoked using Rscript. If I understand the
>> documentation correctly, the following example should work:
>>
>> In file test.R:
>> ? ?options(keep.source=T)
>> ? ?fn<-function(x){x<-x+1}
>> ? ?srcDir<-getSrcDirectory(fn)
>> ? ?print(srcDir)
>>
>> I attempted the following invocations of Rscript:
>> ? ?+ Rscript test.R
>> ? ?+ Rscript<full_path>/test.R
>>
>> I attempted the following invocations using R:
>> ? ?+ source("test.R")
>> ? ?+ Manually entering the function
>>
>> In both attempts, the variable srcDir is a zero-length character
>> vector. Digging into the documentation, I notice that getSrcDirectory()
>> looks for a "srcref" attribute in the function body. In neither R
>> nor Rscript is this attribute set when declaring the function.
>>
>> So: what am I missing?
>>
>> Comments:
>> ? ?+ I have 'keep.source' option set to TRUE in both R and Rscript
>> ? ? ?(irritatingly, it's default is TRUE in R and FALSE in Rscript
>> ? ? ? - why is this?)
>> ? ?+ I have tested this with:
>> ? ? ? ? o R 2.13.1 on Ubuntu 10.10 (server)
>> ? ? ? ? o R 2.13.0 on Windows 7
>>
>> Best wishes,
>> Cormac.
>>
>> ______________________________________________
>> 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.
>