Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling RMarkdown with RStudio: why reading .RProfile?

Tags:

r

rstudio

knitr

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

like image 647
A S Avatar asked Apr 20 '15 15:04

A S


1 Answers

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 (e.g. 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").

like image 50
Yihui Xie Avatar answered Sep 30 '22 09:09

Yihui Xie