0

I wrote a R function for my client which needs to pre-install some packages. To avoid any possible errors at my client's end, I would add some script lines in my function to test whether these required packages installed or not when my client runs it. If not, try to install any of them missed and require it automatically. For example, suppose the following simple function need to preinstall packages 'list("car","zoo","survival")`, how could I script for this purpose?

func<-function(x){
   exp(x)
}
David Z
  • 6,641
  • 11
  • 50
  • 101
  • 4
    Put your function into its own package and include those packages as dependencies. – Thomas Apr 24 '14 at 18:09
  • 2
    Take a look @Thierry's post in this question http://stackoverflow.com/questions/5595512/what-is-the-difference-between-require-and-library – matt_k Apr 24 '14 at 18:09
  • 1
    Would you be more specific or give an answer? Thomas +1 – David Z Apr 24 '14 at 18:11
  • I saw that post, but it just for one package, how to make it work for a list of packages? – David Z Apr 24 '14 at 18:12
  • 1
    Answered here: http://stackoverflow.com/questions/4090169/elegant-way-to-check-for-missing-packages-and-install-them – pak Apr 24 '14 at 18:16

0 Answers0