要在 RI 中处理 excel 文件,请使用 openxlsx 包。工作正常,以及将 xlsx 文件读入 R 以及从 R 中写入这样的文件。直到今天。在我的一个脚本中,我有以下代码:
library(openxlsx)
wb <- createWorkbook()
addWorksheet(wb, sheetName = prog, tabColour = "limegreen")
#define styles
style.1 <- createStyle(fg = "#90EE90") #color even rows
style.2 <- createStyle(fg = "#DAF3EA") #color odd rows
style.1 <- createStyle(fg = "#90EE90")
定义用于输出的样式。从今天开始,这一行和我使用 createStyle 的其他行一样出现错误。错误信息是:
(函数(env,objName)中的错误:“findVar”的参数不是环境。
这可能是由于将 R 和 Rstudio 更新到最新版本造成的吗?更重要的是:我能对这个错误做些什么?
Session info:
R version 3.4.3 (2017-11-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.1
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions. /A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources /lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] bindrcpp_0.2 dplyr_0.7.4 data.table_1.10.4-3 openxlsx_4.0.17
loaded via a namespace (and not attached):
[1] compiler_3.4.3 magrittr_1.5 assertthat_0.2.0 R6_2.2.2 tools_3.4.3
[6] glue_1.2.0 tibble_1.3.4 yaml_2.1.15 Rcpp_0.12.14 pkgconfig_2.0.1
[11] rlang_0.1.4 bindr_0.1
Traceback 给出了下面的结果。
trace(back)
1: (function (env, objName)
{
obj <- get(objName, env)
hasNullPtr <- .Call("rs_hasExternalPointer", obj, TRUE)
if (hasNullPtr) {
val <- "<Object with null pointer>"
desc <- "An R object containing a null external pointer"
size <- 0
len <- 0
}
else {
val <- "(unknown)"
desc <- ""
size <- object.size(obj)
len <- length(obj)
}
class <- .rs.getSingleClass(obj)
contents <- list()
contents_deferred <- FALSE
if (is.language(obj) || is.symbol(obj)) {
val <- deparse(obj)
}
else if (!hasNullPtr) {
if (size > 524288) {
len_desc <- if (len > 1)
paste(len, " elements, ", sep = "")
else ""
if (is.data.frame(obj)) {
val <- "NO_VALUE"
desc <- .rs.valueDescription(obj)
}
else {
val <- paste("Large ", class, " (", len_desc,
capture.output(print(size, units = "auto")),
")", sep = "")
}
contents_deferred <- TRUE
}
else {
val <- .rs.valueAsString(obj)
desc <- .rs.valueDescription(obj)
if (class == "data.table" || class == "ore.frame" ||
class == "cast_df" || class == "xts" || class ==
"DataFrame" || is.list(obj) || is.data.frame(obj) ||
isS4(obj)) {
contents <- .rs.valueContents(obj)
}
}
}
list(name = .rs.scalar(objName), type = .rs.scalar(class),
clazz = c(class(obj), typeof(obj)), is_data = .rs.scalar(is.data.frame(obj)),
value = .rs.scalar(val), description = .rs.scalar(desc),
size = .rs.scalar(size), length = .rs.scalar(len), contents = contents,
contents_deferred = .rs.scalar(contents_deferred))
})(<environment>, "style.1")