我写了一个非常简单的R代码,当我直接在Rmd中运行R-chunks时,它也工作得很好。
library(tidyr)
AirPassengers <- AirPassengers %>%
pivot_longer(-year, names_to = "month", values_to = "passengers")
但是当我尝试编织这个Rmd文件时,报告了以下错误。为什么会这样,报告错误意味着什么?
Error in UseMethod("pivot_longer") :
no applicable method for 'pivot_longer' applied to an object of class "list"
Calls: <Anonymous> ... withCallingHandlers -> withVisible -> eval -> eval -> %>% -> pivot_longer
In addition: Warning messages:
1: replacing previous import 'lifecycle::last_warnings' by 'rlang::last_warnings' when loading 'pillar'
2: replacing previous import 'lifecycle::last_warnings' by 'rlang::last_warnings' when loading 'tibble'
3: package 'pammtools' was built under R version 4.0.5
4: In AirPassengers$year <- as.numeric(rownames(AirPassengers)) :
Coercing LHS to a list
Execution halted
任何帮助都将非常感激!
我谷歌了一下,没有找到任何有用的答案。我很好奇为什么它在当前块中工作得很好,并得到所需的结果,但不是在编织中。还有:错误报告中提到的那行代码只是用来加载tidyr包的。
参考警告信息4,AirPassengers$year <- as.numeric(rownames(AirPassengers))
。我只是在这行之前加上了AirPassengers <- readRDS("AirPassengers.Rds")
,现在它解决了。