Search code examples
rexcelperlxlsx

Cannot read data from an xlsx file in RStudio


I have installed the required packages - gdata and ggplot2 and I have installed perl.

library(gdata)
library(ggplot2)

# Read the data from the excel spreadsheet
df = data.frame(read.xls ("AssignmentData.xlsx", sheet = "Data", header = TRUE, perl = "C:\\Strawberry\\perl\\bin\\perl.exe"))

However when I run this I get the following error:

Error in xls2sep(xls, sheet, verbose = verbose, ..., method = method,  : 
  Intermediate file 'C:\Users\CLAIRE~1\AppData\Local\Temp\RtmpE3UYWA\file8983d8e1efc.csv' missing!
In addition: Warning message:
running command '"C:\STRAWB~1\perl\bin\perl.exe" "C:/Users/Claire1992/Documents/R/win-library/3.1/gdata/perl/xls2csv.pl"  "AssignmentData.xlsx" "C:\Users\CLAIRE~1\AppData\Local\Temp\RtmpE3UYWA\file8983d8e1efc.csv" "Data"' had status 2 
Error in file.exists(tfn) : invalid 'file' argument

Solution

  • Thanks to @Stibu I realised I had to set my work directory. This is the command you use to run in Rstudio; setwd("C/Documents..."). The file path is where the excel file is located.