Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in ls(envir = envir, all.names = private)?

Tags:

r

excel

The below error keeps coming up inconsistently when I try to read excel files into R using the 'XLConnect' package.

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

I have actually run into this error while even using other packages that read excel files like package 'xlsx' and 'xlsReadWrite'. Many times restarting the R session solves this problem, which leads me to think that something else I am doing in my R session is changing the environment and not allowing me to load excel files anymore. Below is the latest example of code that is causing this error. In this case I know that the following coding sequence is causing the error to appear - but why is that happening? And how can I get past this error if I need the chron package.

library("XLConnect")
wb2 <- loadWorkbook("excel_file", create = FALSE)
library(chron)
wb2 <- loadWorkbook("excel_file", create = FALSE)

Anyone else run into this issue before? Any help on this issue is greatly appreciated!

like image 368
abhisarihan Avatar asked Nov 02 '22 21:11

abhisarihan


1 Answers

Before reopening the workbook try removing the reference to previously opened one, so: rm(wb2) wb2 <- loadWorkbook("excel_file", create = FALSE)

Also, make sure that "excel_file" is not open by excel or any other program while you run the R test.

I've seen the same error come up when using XLConnect and the above seemed to help.

like image 94
Andreas Rhode Avatar answered Nov 15 '22 05:11

Andreas Rhode