简体   繁体   中英

Compiling RMarkdown with RStudio: why reading .RProfile?

Why RStudio, when compiling an.HTML from.Rmd, tries to read my .RProfile file?

I mean, I press the "Knit HTML" button, and then it actually tries to execute everything I have in .RProfile , loads every library mentioned there and then fails trying to source external files (I have a bunch of self-coded functions mentioned in .RProfile , lines like source('/Users/me/.rstudio-desktop/lib/lib.stocks.R') , etc.

For now, I literally have to move .RProfile out from the home directory during the compilation (knitting), but there probably should be some kind of option, or something?

Would be grateful for any suggestion:).


OS X 10.8.5, RStudio Version 0.98.1091

That is what .Rprofile does by definition. When R starts, it reads and executes this file. RStudio launches a new R session to compile R Markdown documents, and the R session reads .Rprofile , unless you tell the R session not to do it (eg via R --no-init-file or R --vanilla ), but currently you cannot really control how RStudio launches the R session. I think if (interactive()) mentioned by @rawr is a very good idea, and is what I use routinely as well (I want my non-interactive R sessions to be "clean").

I'm new to using projects in RStudio, so educate me if I'm misunderstanding the question or doing something dumb. But it sounds like the issue is really that your.Rprofile is unnecessarily large for the specific document.

If you create a new project for a given document, they'll have their own.Rprofiles, which can be tailored to the needs of the doc.

More specifically, I made a template that I just copy/paste for each new project I start. It's just a folder that looks like this:

Project Template (folder)

  • Data (folder)
  • Scripts (folder)
  • Outputs (folder)
  • Documentation (folder) New Project.Rproj.Rprofile

The.Rprofile includes tidyverse and other packages I always use, to which I add other packages as required. Of course, if you're working on a large project that requires lots of large and/or homemade packages and you're just trying to make one small document within that project, you'll run into that problem again.

I'm sure you've solved this problem ages ago, but I hope this helps out anyone who (like me) came across this page while troubleshooting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM