Different RProfile for a project

Joel's Avatar

Joel

01 May, 2012 03:06 AM

Is it possible to have R load from a particular RProfile when a project opens (specific to that project)? I assumed this would happen, so I made a new RProfile and put it in the working directory for that project, but it is just loading my default RProfile. I'd like to do this to load specific functions and packages when I open the project. Maybe there is a different way to accomplish this?

Thanks,
Joel

  1. Support Staff 2 Posted by Josh Paulson on 01 May, 2012 02:55 PM

    Josh Paulson's Avatar

    Joel,

    This should be working if you put a different .Rprofile in the root directory of each project. I just tested it and got it working fine. For example if you start a new project in ~/Desktop/foo then you run the following code:

    > file.edit("~/Desktop/foo/.Rprofile")
    

    This will open a new document called .Rprofile and I just put the following commands in to test (note the blank line at the end):

    1) print("Inside the foo project")
    2)
    

    After that, you can switch projects from inside RStudio and it will load the correct .Rprofile. Let me know if you are able to get this working. Just make sure to save it in the root directory of the project (where the foo.Rproj file is as well.).

    Josh

  2. 3 Posted by Joel Martin on 01 May, 2012 03:00 PM

    Joel Martin's Avatar

    I have a .Rprofile in the project directory, but it doesn't seem to be
    loading from it. Do I need to create it with the commands you list below,
    or should it recognize any file called .Rprofile in the working directory
    for the project?

  3. Support Staff 4 Posted by Josh Paulson on 01 May, 2012 05:57 PM

    Josh Paulson's Avatar

    Joel,

    You don't need to use this exact command (it just opens up the file if it exists or creates a new one). Are you naming the file such as foo.Rprofile or is it just called .Rprofile? This would lead to it loading the default .Rprofile if you named it.

    Josh

  4. 5 Posted by Joel Martin on 01 May, 2012 06:25 PM

    Joel Martin's Avatar

    Well, I'm not sure why but when I created the .Rprofile using the step
    file.edit() command you gave me, it now works. File looks exactly the same
    as far as I can tell, but I must have done something wrong with it. Thanks
    for your help.

  5. Support Staff 6 Posted by Josh Paulson on 01 May, 2012 06:30 PM

    Josh Paulson's Avatar

    Joel,

    If you were using notepad or another application it might have saved it as a different file type (text file or something else). In this case it could have added a hidden extension. Either way, glad that you got this working.

    Josh

  6. Josh Paulson closed this discussion on 01 May, 2012 06:30 PM.

Comments are currently closed for this discussion. You can start a new one.