ℙℕℤℝ 2011-08-08 09:12
浏览 362
已采纳

如何卸载一个包不重新启动 r?

I'd like to unload a package without having to restart R (mostly because restarting R as I try out different, conflicting packages is getting frustrating, but conceivably this could be used in a program to use one function and then another--although namespace referencing is probably a better idea for that use).

?library doesn't show any options that would unload a package.

There is a suggestion that detach can unload package, but the following both fail:

detach(vegan)

Error in detach(vegan) : invalid name argument

detach("vegan")

Error in detach("vegan") : invalid name argument

So how do I unload a package?

转载于:https://stackoverflow.com/questions/6979917/how-to-unload-a-package-without-restarting-r

  • 写回答

7条回答 默认 最新

  • perhaps? 2011-08-08 09:19
    关注

    Try this (see ?detach for more details):

    detach("package:vegan", unload=TRUE)
    

    It is possible to have multiple versions of a package loaded at once (for example, if you have a development version and a stable version in different libraries). To detach guarantee that all copies are detached, use this function.

    detach_package <- function(pkg, character.only = FALSE)
    {
      if(!character.only)
      {
        pkg <- deparse(substitute(pkg))
      }
      search_item <- paste("package", pkg, sep = ":")
      while(search_item %in% search())
      {
        detach(search_item, unload = TRUE, character.only = TRUE)
      }
    }
    

    Usage is, for example

    detach_package(vegan)
    

    or

    detach_package("vegan", TRUE)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?

悬赏问题

  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题