问题
I am attempting to follow this easy 2-minute video tutorial on importing an Excel spreadsheet into R as a data frame: http://www.screenr.com/QiN8
I followed each step, including downloading and installing Strawberry Perl (32-bit) on my Win 7 PC, pointing R to my working directory, and entering the following command in R:
Spreadsheet <- read.xls("targetspreadsheet.xls")
I receive this error:
Error in findPerl(verbose = verbose) : perl executable not found. Use perl= argument to specify the correct path. Error in file.exists(tfn) : invalid 'file' argument
Update:
I reset my machine and set the path to Perl:
perl <- "C:/strawberry/perl/bin/perl.exe"
Then I entered this command:
DF <- read.xls("spreadsheet.xls", perl = perl)
The command line returned this error:
Error in xls2sep(xls, sheet, verbose = verbose, ..., method = method, : Intermediate file 'C:\Users\AEID\AppData\Local\Temp\RtmpoXMywa\file18e45ed513c.csv' missing! In addition: Warning message: running command '"C:\STRAWB~1\perl\bin\perl.exe" "C:/Users/AEID/Documents/R/win-library/2.15/gdata/perl/xls2csv.pl" "GFT_show_wip_report(42).xls" "C:\Users\AEID\AppData\Local\Temp\RtmpoXMywa\file18e45ed513c.csv" "1"' had status 2 Error in file.exists(tfn) : invalid 'file' argument
What am I doing wrong?
Thanks in advance for your help!
AME
回答1:
After loading the gdata package using library(gdata)
it clearly says:
gdata: read.xls() will be unable to read Excel XLS and XLSX files gdata: unless the 'perl=' argument is used to specify the location of a gdata: valid perl intrpreter.
So, you need the PATH to the valid perl interpreter. Using windows, as is the case here, you need to check the properties to locate the required perl interpreter.
#set the PATH to perl interpreter
perl <- "C:/strawberry/perl/bin/perl5.18.2.exe"
try1file <- read.xls("my.one.filename.xls", perl = perl)
For multiple xls files:
> length(list.files())
[1] 65
try65files <- lapply(list.files(), ..., perl = perl)
If verbose = TRUE
, at the end of each file it will read:
Loading 'F65.xls'...
Done.
Orignal Filename: F65.xls
Number of Sheets: 1
Writing sheet number 1 ('Sheet1') to file 'C:\Users\FRANKL~1.JOH\AppData\Local\Temp\RtmpeKs3fi\file13dc750950e4.csv'
Minrow=0 Maxrow=32 Mincol=0 Maxcol=16
(Ignored 0 blank lines.)
0
Done.
Reading csv file “C:\Users\FRANKL~1.JOH\AppData\Local\Temp\RtmpeKs3fi\file13dc750950e4.csv” ...
Done.
回答2:
As some other answers say already the problem is that perl.exe is missing. In my case it worked after getting it installed from: http://www.activestate.com/activeperl/downloads and then point to it:
read.xls("bla.xlsx", perl = "C:\\Perl64\\bin\\perl.exe")
回答3:
The problem went away after I ran the following script and restarted the PC:
library(gdata)
installXLSXsupport(perl = 'C:\\strawberry\\perl\\bin\\perl.exe')
回答4:
I have recently got the same problem with gdata
package and Strawberry Perl software under Windows 10. The solution in my case is as follows: (1) uninstall an old version of the Strawberry Perl -- if you try to install new version over the old one, it says that it is not upgradable, (2) install a new version downloaded from this link to C:/Strawberry/
, (3) add C:/Strawberry/perl/bin/perl.exe
to 'Path' in User variables of the Environment Variables window.
回答5:
I also meet the same issue and had been fighting with "error in xls2sep" for 1 hour. to re-install strawberry, does not work.
I finally found out that the excel file was broken. "error in xls2sep" seems to mean the file is broken.
Ning
回答6:
You can try this sytax:
T<-read.xls("Template.xlsx", perl = "C:\\Perl\\bin\\perl.exe")
I found this solution here
http://cran.r-project.org/web/packages/gdata/INSTALL
回答7:
I ran into this issue myself and finally found the culprit. In my initial code i was working with an excel file with 4 sheets, and was operating on the 4th sheet- read.xls(con, perl=prl, sheet=4). My new xlxs file had one sheet, causing the error.
回答8:
R is searching for the xls or xlsx file, but is not finding it. So set the working directory where your Excel file is located (e.g. setwd("C:\....")
) and run any of these script formats:
read.xls("Potato.xls", perl = "C:\\Strawberry\\perl\\bin\\perl.exe")
read.xls("Tomato.xls", perl = "C:\\Strawberry\\perl\\bin\\perl.exe")
read.xls("Potato.xlsx", perl = "C:/Strawberry/perl/bin/perl.exe")
read.xls("Tomato.xlsx", perl = "C:/Strawberry/perl/bin/perl.exe")
回答9:
Make sure your path variable is NOT named "perl". I renamed it to prl and success!
This did NOT work:
perl <- "C:/Strawberry/perl/bin/perl.exe"
excel_gdata <- read.xls(url_xls, perl)
Error in findPerl(verbose = verbose) :
perl executable not found. Use perl= argument to specify the correct path.
Error in file.exists(tfn) : invalid 'file' argument
This works!
prl <- "C:/Strawberry/perl/bin/perl.exe"
excel_gdata <- read.xls(url_xls, prl)
回答10:
In my case, I got the similar message:
Error in xls2sep(xls, sheet, verbose = verbose, ..., method = method, :
Intermediate file 'C:\Users\dddd\AppData\Local\Temp\Rtmp6DG4Cr\file1ce018647411.csv' missing!
In addition: Warning message:
running command '"C:\Perl64\bin\PERL52~1.EXE" "C:/Users/dddd/Documents/R/win-library/3.4/gdata/perl/xls2csv.pl" "D:/dddd/mlj/Results/xxxx.xlsx" "C:\Users\dddd\AppData\Local\Temp\Rtmp6DG4Cr\file1ce018647411.csv" "1"' had status 13
Error in file.exists(tfn) : invalid 'file' argument
I figured out the solution by closing the Excel table, which cannot be opened by both Excel and R at the same time.
来源:https://stackoverflow.com/questions/10940224/gdata-package-perl-issue