[R] Why does R start in wrong working directory despite R_USER setting?
Jim Lemon
drjimlemon at gmail.com
Sat Aug 8 00:56:43 CEST 2015
Hi Mauricio,
You can also run a directory selection file by including something like this:
source("SelectAnalysis.R")
in the .First function (see "An Introduction to R", section 10.8
Customizing the environment). Mine currently looks like this:
cat("(A)custudy\n(I)nterval analysis\n(O)mbo
mapping\nR\n(C)ourse\nStressaly(Z)er\n")
answer<-toupper(readline("Choose the project - "))
if(answer=="A") setwd("/home/jim/research/im/acustudy")
if(answer=="I") setwd("/home/jim/research/interval_analysis")
if(answer=="O") setwd("/home/jim/research/ombo/mapping")
if(answer=="R") setwd("/home/jim/R")
if(answer=="C") setwd("/home/jim/bitwrit/R_programming_course")
if(answer=="Z") setwd("/home/jim/research/stressalyser/naomi")
print(list.files(pattern="[.]R"))
options(browser="konqueror",editor="kwrite",show.signif.stars=FALSE)
This should work on any system, regardless of your privileges.
Jim
On Sat, Aug 8, 2015 at 4:02 AM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote:
> Not really a question about R, but you can make a Windows shortcut that sets the directory where you want it.
>
> My preference is to start in different working directories depending on which project I am working on. R_USER is not a project directory. One way to do that is to double-click on an RData file located where you want to start. Another way is to create a new shortcut in each directory. Another way is to add a line to your script that sets the directory appropriately, though that makes sharing the scripts harder. Another way is to use RStudio projects.
> ---------------------------------------------------------------------------
> Jeff Newmiller The ..... ..... Go Live...
> DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
> Live: OO#.. Dead: OO#.. Playing
> Research Engineer (Solar/Batteries O.O#. #.O#. with
> /Software/Embedded Controllers) .OO#. .OO#. rocks...1k
> ---------------------------------------------------------------------------
> Sent from my phone. Please excuse my brevity.
>
> On August 7, 2015 12:31:16 PM EDT, Mauricio Cornejo via R-help <r-help at r-project.org> wrote:
>>Hi
>>After launching newly-installed R 3.2.1 (on Windows 7), I run the
>>following two commands:
>>> getwd()[1] "C:/ProgramData/Microsoft/Windows/Start Menu/Programs/R"
>>> Sys.getenv('R_USER')[1] "C:\\Users\\<my username>\\Documents"
>>I would like the startup working directory to be that pointed to by
>>R_USER.
>>I don't have administrative access to the machine.
>>Many thanks for any insight anyone can provide.
>>Mauricio
>> [[alternative HTML version deleted]]
>>
>>______________________________________________
>>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>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 -- To UNSUBSCRIBE and more, see
> 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.
More information about the R-help
mailing list