简体   繁体   English

XLConnect'envir'错误

[英]XLConnect 'envir' error

I manage a number of Excel reports, and I use R to do the preprocessing and write the output report. 我管理许多Excel报告,并使用R进行预处理并编写输出报告。 It's great because all I have to do is run the R function and distribute the reports, and the rest of the report writing is inactive time. 太好了,因为我要做的就是运行R函数并分发报告,而其余的报告编写都处于非活动时间。 The reports need to be in Excel format because it is the easiest to disseminate and the audience is large and non-technical. 报告必须采用Excel格式,因为它最易于分发,并且受众众多且非技术性。 Once the data is pre-processed, I do this very, very simply using XLConnect: 在对数据进行预处理之后,我将非常非常简单地使用XLConnect来执行此操作:

file.copy(from = template,
          to = newFileName)

writeWorksheetToFile(file = newFileName,
                     data = newData,
                     sheet = "Data",
                     clearSheets = T)

However, one of my reports began throwing this error when I attempted to write the new data: 但是,当我尝试写入新数据时,我的一份报告开始引发此错误:

Error in ls(envir = envir, all.names = private) : 
invalid 'envir' argument

Furthermore, before throwing the error, the function ties up R for 15 minutes. 此外,在引发错误之前,该函数将R绑定15分钟。 The normal writing time is less than 10 seconds. 正常写入时间少于10秒。 I must confess, I don't understand what this error even means, and it did not succumb to my usual debugging methods or to any other SO solution. 我必须承认,我什至不理解该错误的含义,并且它也没有屈服于我通常的调试方法或任何其他SO解决方案。

I've noticed that others have referred to rJava (reinstalling this package didn't work) and to a Java cache of log files (not sure where this would be located on Mac). 我注意到,其他人已经提到过rJava(重新安装此程序包无效)和日志文件的Java缓存(不确定在Mac上的位置)。 I'm especially confused as the report ran with no problems just one day earlier using precisely the same process, AND my other reports using the exact same process still work just fine. 我特别困惑,因为一天前使用完全相同的流程报告就没有问题,而我使用完全相同的流程的其他报告仍然可以正常工作。

I didn't update Java or R or my OS, or debug/rewrite any of the R code. 我没有更新Java或R或我的操作系统,也没有调试/重写任何R代码。 So, starting from the beginning - how can I investigate this 'envir' error? 因此,从头开始-如何调查此“ envir”错误? What would you do if you were in my shoes? 如果你穿着我的鞋子,你会怎么做? I've been working on this for a couple days and I'm stumped. 我已经为此工作了几天,但感到很困惑。

I'm happy to provide extra information if it will provide better context for more discerning programmers than myself :) 如果能为比我自己更多的眼光敏锐的程序员提供更好的上下文,我很乐意提供更多信息:)

Update: My previous answer (below) did not, in fact, fix this intermittent error (which as the OP points out is extremely difficult to unpick due to the Java dependency). 更新:我以前的回答(如下)并没有解决此间歇性错误(正如OP指出的那样,由于Java依赖性,它很难被取消)。 Instead, I followed the advice given here and migrated from the XLConnect package to openxlsx , which sidesteps the problem entirely. 相反,我遵循此处给出的建议,从XLConnect包迁移到openxlsx ,这完全避开了问题。

Previous answer: I've been frustrated by precisely this error for a while, including the apparent intermittency and the tying up of R for several minutes when writing a workbook. 以前的答案:一段时间以来,我一直对这个错误感到沮丧,其中包括明显的间歇性以及在编写工作簿时将R捆绑了几分钟。

I just realised what the problem was: the length of the name of an Excel worksheet appears to be limited to 31 characters, and my R code was generating worksheet names in excess of this limit. 我只是意识到问题出在哪里:Excel工作表的名称长度似乎限制为31个字符,而我的R代码生成的工作表名称超出了此限制。

Just to be clear, I'm referring to the names of the individual tabbed sheets within an Excel workbook, not the filename of the workbook itself. 为了清楚起见,我指的是Excel工作簿中各个选项卡式工作表的名称,而不是工作簿本身的文件名。

Trimming each worksheet name to no more than 31 characters fixed this error for me. 将每个工作表名称修剪到不超过31个字符对我来说解决了此错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM