【问题标题】:Error while knitting a LaTeX file: could not find function "as"编织 LaTeX 文件时出错:找不到函数“as”
【发布时间】:2018-06-13 10:22:51
【问题描述】:

我正在尝试编织一个嵌入在扩展名为 Rnw 的乳胶文件中的块。

library(ggplot2)
library(flexclust)
library(arules)

data(Groceries)

Gr <- Groceries[, itemFrequency(Groceries) > 0.02]
grc <- as(Gr, "matrix")

我得到这个错误:

#Error in as(Gr, "matrix") could not find function "as"

相同的命令在 R 中运行良好

有什么想法吗?

【问题讨论】:

  • 不是 as() 来自方法包吗?
  • 有趣的是,在 knitr 主体中添加库(方法)解决了这个问题。向 Wimpel 致敬,谢谢!

标签: r latex knitr


【解决方案1】:

When in doubt, try to upgrade your software packages. 如果您使用的是最新版本的 R (>= 3.5.0),则不需要library(methods),因为它会默认加载(附加)。这个问题(Rscript 不加载方法has existed in base R for many years 直到今年才让许多用户感到惊讶/困惑。如果您必须使用旧版本的 R,则需要明确地使用 library(methods)

【讨论】:

    猜你喜欢
    • 2022-10-24
    • 2019-02-05
    • 1970-01-01
    • 2017-12-04
    • 1970-01-01
    • 2021-02-08
    • 2022-01-23
    • 2021-08-06
    • 1970-01-01
    相关资源
    最近更新 更多