2

I find it annoying that I have to click Tools -> Update Packages every time I load RStudio. I could use update.packages(c("ggplot2")) for instance to update my packages in .RProfile, but the issue is that it won't look for other packages (dependencies). For instance, I have to update "seriation" and "digest" package every time I start RStudio, and these packages are not loaded by me at start-up. Does anyone have code to automatically check and update all packages at start-up ? If so, can you please share here? I extensively googled this topic and searched through SO, and it seems that popular opinion is to use RStudio's menu. Here's the thread I am referring to: How to update R2jags in R?

One way I can think of doing this is in .RProfile:

a<-installed.packages()
b<-data.frame(a[,1])

and then calling this function: https://gist.github.com/stevenworthington/3178163

However, I am not quite sure whether this is the most optimal method.

Another linked thread is: Load package at start-up

I created the thread above. I'd appreciate any thoughts.

Community
  • 1
  • 1
watchtower
  • 4,140
  • 14
  • 50
  • 92
  • 1
    This is a bad idea. You will realize that once you need to create and print out some result just before an important meeting and just then a package update breaks your code. – Roland Aug 08 '16 at 06:16
  • I see. Great thought Roland! I am new to R (and have switched from STATA)--I've been programming for only about 10 days now. Do you think such issues are very common? – watchtower Aug 08 '16 at 06:18

1 Answers1

1

i found this on internet(don't remember where) when i was struggling with the same problem, though you still need to run this program . Hope this helps .

all.packages <- installed.packages()
r.version <- paste(version[['major']], '.', version[['minor']], sep = '')

for (i in 1:nrow(all.packages))
{
  package.name <- all.packages[i, 1]
  package.version <- all.packages[i, 3]
  if (package.version != r.version)
  {
    print(paste('Installing', package.name))
    install.packages(package.name)
  }
}
Pankaj Kaundal
  • 1,012
  • 3
  • 13
  • 25