相关疑难解决方法(0)

如果包已经加载,那么在函数内部需要包的影响是什么?

在非常频繁调用的函数内包含library/ require语句是否有任何不利影响?

使用的时间似乎相当可以忽略不计,但我每隔几分钟调用一次这个功能,我想知道重复require呼叫是否有任何缺点?
请注意,该功能只是一个个人工具,并没有被共享.即,我是唯一使用它的人

顺便说一下,任何关于为什么library一半的见解都慢了require?我的印象是他们是同义词.

  WithREQUIRE <- function(x) {
    require(stringr)
    str_detect(x, "hello")
  }

  WithLIBRARY <- function(x) {
    library(stringr)
    str_detect(x, "hello")
  }

  Without <- function(x) {
    str_detect(x, "hello")
  }

  x <- "goodbye"

  library(rbenchmark)
  benchmark(WithREQUIRE(x), WithLIBRARY(X), Without(x), replications=1e3, order="relative")

  #            test replications elapsed relative user.self sys.self
  #      Without(x)         1000   0.592    1.000     0.262    0.006
  #  WithREQUIRE(x)         1000   0.650    1.098     0.295    0.015
  #  WithLIBRARY(X)         1000   1.359    2.296     0.572    0.024
Run Code Online (Sandbox Code Playgroud)

r require

14
推荐指数
1
解决办法
5832
查看次数

标签 统计

r ×1

require ×1