【发布时间】:2011-11-22 06:18:18
【问题描述】:
在解决另一个问题时遇到了这个问题:
我可以通过以下方式删除所有 R 对象:
rm(list = ls(all = TRUE))
是否有等效的命令可以在工作会话期间分离已安装的包?
> sessionInfo()
R version 2.12.2 (2011-02-25)
Platform: i386-pc-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
需要(ggplot2)
Loading required package: ggplot2
Loading required package: reshape
Loading required package: plyr
Attaching package: 'reshape'
The following object(s) are masked from 'package:plyr':
round_any
Loading required package: grid
Loading required package: proto
sessionInfo()
R version 2.12.2 (2011-02-25)
Platform: i386-pc-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] grid stats graphics grDevices utils datasets methods
[8] base
other attached packages:
[1] ggplot2_0.8.9 proto_0.3-9.1 reshape_0.8.4 plyr_1.4
我尝试过这种方式,尽管它在不是全局解决方案中也有效:
pkg <- c("package:ggplot2_0.8.9", "package:proto_0.3-9.1", "package:reshape_0.8.4", "package:plyr_1.4")
detach(pkg, character.only = TRUE)
Error in detach(pkg, character.only = TRUE) : invalid 'name' argument
In addition: Warning message:
In if (is.na(pos)) stop("invalid 'name' argument") :
the condition has length > 1 and only the first element will be used
我正在寻找的是全球性的,例如:
rm(list = ls(all = TRUE))
对于对象,期望它不会删除附加的基础包
谢谢;
【问题讨论】:
-
不是你的问题是无效的,而是为什么不重启R?
-
@Aaron 因为你不应该有太多 ;-) 传递
R CMD check一个包应该干净地卸载自己,所以 R Core 期望这是可能的,并且可能希望这样做。 -
@Aaron,我认为有时在某些包引起或可能引起干扰时让会话继续可能很有用,但在前面的步骤中使用...
-
不可能将 R 恢复到新的状态。我已经和 John Chambers 讨论过这个问题,对于 S4 类/方法注册来说尤其困难。