# Function that checks for new package versions and installs them if desired

I’m trying to write a function which checks if a newer version of the packages in the library is available, then asks if this new version should be installed and if the input is "Yes" the new version is installed, with input "No" not.

I would like to embed the function directly into .Rprofile, so that the necessary packages are loaded when opening the Project. Currently I have the following function in .Rprofile:

`## Default repo local({r <- getOption("repos") r["CRAN"] <- "https://stat.ethz.ch/CRAN/" options(repos=r) }) paste("Welcome to the R Project.") source("./library.R") for ( i in list.of.packages){ if (i %in% utils::old.packages()[,"Package"] == FALSE) { cat("The latest version of the following package is already installed: ") print(i) } if (i %in% utils::old.packages()[,"Package"] == TRUE) { cat("A newer version of the following package is available:") print(i) cat("Should a newer version of the package be installed? [Yes/No]") x <- readline("Should a newer version of the package be installed? [Yes/No]") if (x %in% c("Yes", "Y")==TRUE) { install.packages(i) } else(cat("The current version of the package is kept.")) } } rm(list=ls()) `

The file "library" contains this:

`list.of.packages <- c("ggplot2", "car") lapply(X = list.of.packages, library, character.only = TRUE) `

The output looks like this:

`[1] "Welcome to the R Project." Loading required package: carData The latest version of the following package is already installed: [1] "ggplot2" A newer version of the following package is available:[1] "car" Should a newer version of the package be installed? [Yes/No][Workspace loaded from ~/.RData] > N The current version of the package is kept. `

Now I would like to remove the workspace message. Can someone tell me how to proceed?

Thank you very much