11

I have a global ~/.Rprofile file and another .Rprofile file located in my project's current working directory and both of the have the following contents:

.First() <- function() {
options(rstudio.markdownToHTML = 
  function(inputFile, outputFile) {      
    system(paste("pandoc", shQuote(inputFile), "-s --webtex -o", shQuote(outputFile)))
  }
)  
}

Unfortunately, when I open the RStudio app neither of them appear to be working. The aim of what I'm trying to do is to make the "Knit HTML" button render the Markdown file, which has inline LaTeX, process through Pandoc using webtex as the LaTeX renderer.

Does anyone know how I check whether my .Rprofile files are loading at startup?

Thanks for any help!

POST ANSWER EDIT (after Josh's answer): For clarity, my working project's .Rprofile file (which works) now reads as such:

options(rstudio.markdownHTML =
  function(inputFile, outputFile) {
    system(paste("pandoc", shQuote(inputFie), "-s --webtex -o", shQuote(outputFile)))
  }
)
 \\ you will need to end with a blank carriage return underneath
hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
rsacc
  • 723
  • 1
  • 8
  • 11

1 Answers1

10

The R docs should help to see how to deal with .Rprofiles. Execute the following at the console:

> ?Startup

The relevant portion of this indicates that you need to put your project .Rprofile in the initial working directory that will be loaded when starting the project. Thus if your project is ~/foo/foobar.Rproj, then you should have your profile be ~/foo/.Rprofile and make sure that when starting up, the initial working directory is ~/foo/. You can see this in the title bar at the top of the console pane in RStudio.

Also to confirm that the correct .Rprofile is actually being loaded, I would personally put in a test to see which (if any) profile is being picked up. For example, include:

print("This is the Rprofile inside the foo project!")

Here is another example about getting this to work:

http://support.rstudio.org/help/discussions/suggestions/1095-different-rprofile-for-a-project#comment_15690293

Finally, if the correct .Rprofile is being loaded inside the project, then there must be something wrong with your code. Looks like you got this from our docs though, so if you get the profile loaded, and continue to have problems, please let us know. You can post a new discussion on our support thread.

Josh

Product Manager - RStudio

Josh Paulson
  • 527
  • 5
  • 6
  • Hi Josh, thanks for your help. I appended the `print("...")` command to the end of my existing project's `.Rprofile` file and after reopening the RStudio app found that the console was showing an error: `.First() <- function() { invalid (NULL) left side of assignment rstudio`, to which I removed the `.First() <- function() {}` call and after saving the `.RProfile` file I reopened the RStudio app and while I **didn't** get any print output to the console, I did notice that the "KnitHTML" button worked properly according to the Pandoc `.Rprofile` setting. Thanks so much for your help. – rsacc Nov 29 '12 at 22:13
  • 2
    Further to all this, I was able to get the `print` function to work when I added a carriage return at the end of my `.Rprofile` file. Just as you have illustrated at the link you've posted Josh. Thanks again for your help. – rsacc Dec 11 '12 at 02:37
  • 5
    Is it possible to have a global Rprofile? There is the file Rprofile.site in the R/etc directory, but Rstudio doesn't seem to load it. I would like to load some libraries which I use most often to be loaded regardless of the project, and some functions for customized pandoc output. – Maxim.K Sep 25 '13 at 16:04
  • @Maxim.K Rstudio does load Rprofile.site (or rather, lauches a R session which sources it). I have a custom Rprofile.site and i work with Rstudio. If it does not work, try checking if Rprofile.site is where it should be. You can check the install directory of R by using `R.home()`. The Rprofile should be in etc/. (e.g. C:\Users\antoine_sac\Program Files\R\R-3.2.2\etc) – asachet Nov 23 '15 at 13:32
  • 1
    My simple .Rprofile had one line, `message("Welcome!")`, but didn't work. Solution was to include a carriage return at the end of the file (as noted above). – Ben Nov 30 '18 at 18:04
  • I add to that that sometimes your profile is indeed found and loaded but there is an error in it which stops execution and explains why some of your options are not set and your init variables missing – Hugues Feb 04 '23 at 18:16