程序go 2011-08-08 09:12 采纳率: 100%
浏览 333
已采纳

如何卸载一个包不重新启动 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条回答 默认 最新

  • ℙℕℤℝ 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 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services