Setting up a .Rprofile file

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Setting up a .Rprofile file

Bruce Ratner PhD
Hi R'ers:
I would like to setting up a .Rprofile file with
setwd("C:/R_WorkDir")
set.seed(12345)
options (prompt "> R ")

---
Can you help providing the code or instructive link, I've find many links, but I can't figure it out?

Thanks.
Bruce

______________
Bruce Ratner PhD
The Significant Statistician™
(516) 791-3544
Statistical Predictive Analytics -- www.DMSTAT1.com
Machine-Learning Data Mining -- www.GenIQ.net

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Setting up a .Rprofile file

Enrico Schumann-2
On Thu, 23 Mar 2017, Bruce Ratner PhD writes:

> Hi R'ers:
> I would like to setting up a .Rprofile file with
> setwd("C:/R_WorkDir")
> set.seed(12345)
> options (prompt "> R ")
>
> ---
> Can you help providing the code or instructive link,
> I've find many links, but I can't figure it out?
>
> Thanks.
> Bruce
>

Quoting from ?Startup:

,----
| [...] unless ‘--no-init-file’ was given, R searches
| for a user profile, a file of R code.  The path of
| this file can be specified by the ‘R_PROFILE_USER’
| environment variable (and tilde expansion will be
| performed).  If this is unset, a file called
| ‘.Rprofile’ is searched for in the current directory
| or in the user's home directory (in that order).  The
| user profile file is sourced into the workspace.
`----

--
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Setting up a .Rprofile file

Bruce Ratner PhD
Henrico:
Thanks for quick reply.
However, one last question:
If I want to change working directory, and put setwd() in the Rprofile file, logically R will not know where the be work directory is, correct?

So, should I install R in my preferred working directory?

Thanks again, in advance.
Bruce


______________
Bruce Ratner PhD
The Significant Statistician™
(516) 791-3544
Statistical Predictive Analytics -- www.DMSTAT1.com
Machine-Learning Data Mining -- www.GenIQ.net



> On Mar 24, 2017, at 3:48 AM, Enrico Schumann <[hidden email]> wrote:
>
> On Thu, 23 Mar 2017, Bruce Ratner PhD writes:
>
>> Hi R'ers:
>> I would like to setting up a .Rprofile file with
>> setwd("C:/R_WorkDir")
>> set.seed(12345)
>> options (prompt "> R ")
>>
>> ---
>> Can you help providing the code or instructive link,
>> I've find many links, but I can't figure it out?
>>
>> Thanks.
>> Bruce
>>
>
> Quoting from ?Startup:
>
> ,----
> | [...] unless ‘--no-init-file’ was given, R searches
> | for a user profile, a file of R code.  The path of
> | this file can be specified by the ‘R_PROFILE_USER’
> | environment variable (and tilde expansion will be
> | performed).  If this is unset, a file called
> | ‘.Rprofile’ is searched for in the current directory
> | or in the user's home directory (in that order).  The
> | user profile file is sourced into the workspace.
> `----
>
> --
> Enrico Schumann
> Lucerne, Switzerland
> http://enricoschumann.net
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Setting up a .Rprofile file

Enrico Schumann-2
On Fri, 24 Mar 2017, Bruce Ratner PhD writes:

> Henrico:
> Thanks for quick reply.
> However, one last question:
> If I want to change working directory, and put setwd() in the Rprofile
> file, logically R will not know where the be work directory is,
> correct?
>
> So, should I install R in my preferred working directory?
>
> Thanks again, in advance.
> Bruce
>

Hm, I think I don't understand what you mean here. Where R
is installed and where it is run are (usually) not the same
places.

Let $ be a shell prompt, and let > be the R
prompt. Then:

  $ cd /tmp/
  $ R -q
  > getwd()
  [1] "/tmp"
  > q("no")
  $ cd ~/Documents/
  $ R -q
  > getwd()
  [1] "~/Documents"

Now I write into my "~./Rprofile" file:

  setwd("~/Downloads")

$ cd /tmp/
$ R -q
> getwd()
[1] "~/Downloads"


But maybe I am completely misunderstanding what you
mean....

Kind regards
     Enrico


>
>
>> On Mar 24, 2017, at 3:48 AM, Enrico Schumann <[hidden email]> wrote:
>>
>> On Thu, 23 Mar 2017, Bruce Ratner PhD writes:
>>
>>> Hi R'ers:
>>> I would like to setting up a .Rprofile file with
>>> setwd("C:/R_WorkDir")
>>> set.seed(12345)
>>> options (prompt "> R ")
>>>
>>> ---
>>> Can you help providing the code or instructive link,
>>> I've find many links, but I can't figure it out?
>>>
>>> Thanks.
>>> Bruce
>>>
>>
>> Quoting from ?Startup:
>>
>> ,----
>> | [...] unless ‘--no-init-file’ was given, R searches
>> | for a user profile, a file of R code.  The path of
>> | this file can be specified by the ‘R_PROFILE_USER’
>> | environment variable (and tilde expansion will be
>> | performed).  If this is unset, a file called
>> | ‘.Rprofile’ is searched for in the current directory
>> | or in the user's home directory (in that order).  The
>> | user profile file is sourced into the workspace.
>> `----
>>

--
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Setting up a .Rprofile file

Jeff Newmiller
OP is on some variant of MSWindows, which doesn't use a Bash shell, so the syntax of that example is a bit foreign, Enrico.

I would say that the concept of using .Rprofile to change directories is ill-advised, since having ALL of your R work in one place is not sustainable. However you can make one or more clickable icons (shortcuts) on your desktop or start menu with the Startup Directory property set to the directory you want to work in. You can modify a shortcut made by the installer, or  hold the Alt key down while dragging the RGui.exe icon to some convenient place, and use the right-click popup menu to change Properties.

I used to create a .RData file in the directory I wanted to work in and double click that to get R started in that directory, but the side effects of loading objects into the R global environment can really confuse things and create puzzling behaviour if that file gets changed. These days I use RStudio and double click on a .Rproj (project) file to get RStudio going with the directory set to where that file is without mucking with the global environment.
--
Sent from my phone. Please excuse my brevity.

On March 24, 2017 3:03:34 AM PDT, Enrico Schumann <[hidden email]> wrote:

>On Fri, 24 Mar 2017, Bruce Ratner PhD writes:
>
>> Henrico:
>> Thanks for quick reply.
>> However, one last question:
>> If I want to change working directory, and put setwd() in the
>Rprofile
>> file, logically R will not know where the be work directory is,
>> correct?
>>
>> So, should I install R in my preferred working directory?
>>
>> Thanks again, in advance.
>> Bruce
>>
>
>Hm, I think I don't understand what you mean here. Where R
>is installed and where it is run are (usually) not the same
>places.
>
>Let $ be a shell prompt, and let > be the R
>prompt. Then:
>
>  $ cd /tmp/
>  $ R -q
>  > getwd()
>  [1] "/tmp"
>  > q("no")
>  $ cd ~/Documents/
>  $ R -q
>  > getwd()
>  [1] "~/Documents"
>
>Now I write into my "~./Rprofile" file:
>
>  setwd("~/Downloads")
>
>$ cd /tmp/
>$ R -q
>> getwd()
>[1] "~/Downloads"
>
>
>But maybe I am completely misunderstanding what you
>mean....
>
>Kind regards
>     Enrico
>
>
>>
>>
>>> On Mar 24, 2017, at 3:48 AM, Enrico Schumann <[hidden email]>
>wrote:
>>>
>>> On Thu, 23 Mar 2017, Bruce Ratner PhD writes:
>>>
>>>> Hi R'ers:
>>>> I would like to setting up a .Rprofile file with
>>>> setwd("C:/R_WorkDir")
>>>> set.seed(12345)
>>>> options (prompt "> R ")
>>>>
>>>> ---
>>>> Can you help providing the code or instructive link,
>>>> I've find many links, but I can't figure it out?
>>>>
>>>> Thanks.
>>>> Bruce
>>>>
>>>
>>> Quoting from ?Startup:
>>>
>>> ,----
>>> | [...] unless ‘--no-init-file’ was given, R searches
>>> | for a user profile, a file of R code.  The path of
>>> | this file can be specified by the ‘R_PROFILE_USER’
>>> | environment variable (and tilde expansion will be
>>> | performed).  If this is unset, a file called
>>> | ‘.Rprofile’ is searched for in the current directory
>>> | or in the user's home directory (in that order).  The
>>> | user profile file is sourced into the workspace.
>>> `----
>>>
>
>--
>Enrico Schumann
>Lucerne, Switzerland
>http://enricoschumann.net
>
>______________________________________________
>[hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Setting up a .Rprofile file

Bert Gunter-2
In reply to this post by Bruce Ratner PhD
Inline.

Cheers,

Bert

On Fri, Mar 24, 2017 at 2:36 AM, Bruce Ratner PhD <[hidden email]> wrote:
> Henrico:
> Thanks for quick reply.
> However, one last question:
> If I want to change working directory, and put setwd() in the Rprofile file, logically R will not know where the be work directory is, correct?

No. See ?setwd . It requires a dir argument and will therefore give an
error if one is not supplied. Nothing to do with "knowing" what the
current working directory is.
>
> So, should I install R in my preferred working directory?

No (imho, anyway). Your working directory may change over time,
depending on how you organize things of course.

Please re-read the advice you have been given as well as ?startup.

Cheers,
Bert


>
> Thanks again, in advance.
> Bruce
>
>
> ______________
> Bruce Ratner PhD
> The Significant Statistician™
> (516) 791-3544
> Statistical Predictive Analytics -- www.DMSTAT1.com
> Machine-Learning Data Mining -- www.GenIQ.net
>
>
>
>> On Mar 24, 2017, at 3:48 AM, Enrico Schumann <[hidden email]> wrote:
>>
>> On Thu, 23 Mar 2017, Bruce Ratner PhD writes:
>>
>>> Hi R'ers:
>>> I would like to setting up a .Rprofile file with
>>> setwd("C:/R_WorkDir")
>>> set.seed(12345)
>>> options (prompt "> R ")
>>>
>>> ---
>>> Can you help providing the code or instructive link,
>>> I've find many links, but I can't figure it out?
>>>
>>> Thanks.
>>> Bruce
>>>
>>
>> Quoting from ?Startup:
>>
>> ,----
>> | [...] unless ‘--no-init-file’ was given, R searches
>> | for a user profile, a file of R code.  The path of
>> | this file can be specified by the ‘R_PROFILE_USER’
>> | environment variable (and tilde expansion will be
>> | performed).  If this is unset, a file called
>> | ‘.Rprofile’ is searched for in the current directory
>> | or in the user's home directory (in that order).  The
>> | user profile file is sourced into the workspace.
>> `----
>>
>> --
>> Enrico Schumann
>> Lucerne, Switzerland
>> http://enricoschumann.net
>>
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Setting up a .Rprofile file

Henrik Bengtsson-5
In reply to this post by Bruce Ratner PhD
R for Windows is a bit peculiar where it locates your .Rprofile file,
or rather what it consider to be your home directory.  If you look
from within R, the file you do want to create / edit is:

> f <- normalizePath("~/.Rprofile", mustWork = FALSE)
> f
[1] "C:\\Users\\joe\\Documents\\.Rprofile"

For instance, to change what your R prompt looks you can add this from
within R as:

> cat('options(prompt = "> R ")\n', file = f, append = TRUE)

Hope this helps

Henrik

On Fri, Mar 24, 2017 at 2:36 AM, Bruce Ratner PhD <[hidden email]> wrote:

> Henrico:
> Thanks for quick reply.
> However, one last question:
> If I want to change working directory, and put setwd() in the Rprofile file, logically R will not know where the be work directory is, correct?
>
> So, should I install R in my preferred working directory?
>
> Thanks again, in advance.
> Bruce
>
>
> ______________
> Bruce Ratner PhD
> The Significant Statistician™
> (516) 791-3544
> Statistical Predictive Analytics -- www.DMSTAT1.com
> Machine-Learning Data Mining -- www.GenIQ.net
>
>
>
>> On Mar 24, 2017, at 3:48 AM, Enrico Schumann <[hidden email]> wrote:
>>
>> On Thu, 23 Mar 2017, Bruce Ratner PhD writes:
>>
>>> Hi R'ers:
>>> I would like to setting up a .Rprofile file with
>>> setwd("C:/R_WorkDir")
>>> set.seed(12345)
>>> options (prompt "> R ")
>>>
>>> ---
>>> Can you help providing the code or instructive link,
>>> I've find many links, but I can't figure it out?
>>>
>>> Thanks.
>>> Bruce
>>>
>>
>> Quoting from ?Startup:
>>
>> ,----
>> | [...] unless ‘--no-init-file’ was given, R searches
>> | for a user profile, a file of R code.  The path of
>> | this file can be specified by the ‘R_PROFILE_USER’
>> | environment variable (and tilde expansion will be
>> | performed).  If this is unset, a file called
>> | ‘.Rprofile’ is searched for in the current directory
>> | or in the user's home directory (in that order).  The
>> | user profile file is sourced into the workspace.
>> `----
>>
>> --
>> Enrico Schumann
>> Lucerne, Switzerland
>> http://enricoschumann.net
>>
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.