Getting .Rprofile to Load at Startup

不羁的心 提交于 2019-12-01 14:31:01

问题


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

回答1:


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



来源:https://stackoverflow.com/questions/13633876/getting-rprofile-to-load-at-startup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!