Prevent RStudio from loading namespaces at startup

It appears that this question was asked two-and-half years ago, and got no useful answers. Perhaps we can do better this time.

When I open RStudio by double-clicking on an Rmd file, it clearly peeks into the code, sees which libraries will eventually be used, and loads their namespaces. Even worse, if RStudio remembers that other Rmd files were open when I last used it, it also peeks into all of their code and loads all their (ir)relevant namespaces. I find this behavior to be a bug rather than a feature. How can I prevent this behavior?

This kind of thing does not happen if I open the R GUI. It does not happen if I open a script in ESS.

This behavior also gives misleading information if I knit an Rmd file and end it with a "sessionInfo()" command in order to document which packages were needed when the script was run. Yes, it correctly lists the namespaces that were loaded. But it should not load and should not list namespaces that were only loaded because a different script was open in the session where the knit was performed.

If memory serves, this is a side effect of RStudio's diagnostic tools. Do you still see the problem if you...

  • turn off missing package/library detection? (in Tools > Options > Code > Diagnostics)
  • turn off diagnostics entirely? (same page)

Thanks for the reply.

If you turn off missing package detection, it still loads the namespaces.

If you completely turn off R diagnostics, it does NOT load the namespaces.

So, this provides the answer I was looking for. (I'm not sure if I had ever used any of the diagnostics other than the missing package detection, and I don't mind waiting to have to install missing packages until te "library" call fails to find it.)


I hate to have to reply to my own post....

But the correct answer is that you must turn off both "R diagnostics" and "missing package detection". Activating either one by itself (or together) will cause namespaces to be loaded automatically.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.