2019年6月3日 星期一

卸載使用中的R套件

開啟一個R以後,想要移除所有的變數可以下指令:
  • rm(list = ls())
若是要卸載所有的套件,可以用下面的指令:
  • lapply(paste('package:', names(sessionInfo()$otherPkgs), sep=""), detach, character.only=TRUE, unload=TRUE)
或是寫成一個function,方法如下:
detachAllPackages <- function() {
  basic.packages <- c("package:stats","package:graphics","package:grDevices","package:utils","package:datasets","package:methods","package:base")
  package.list <- search()[ifelse(unlist(gregexpr("package:",search()))==1,TRUE,FALSE)]
  package.list <- setdiff(package.list,basic.packages)
  if (length(package.list)>0)  for (package in package.list) detach(package, character.only=TRUE)
}
detachAllPackages()


參考資料:

_EOF_

沒有留言:

張貼留言