Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RStudio read.xl working directory error

Tags:

r

readxl

Hi guys I'm having difficulty loading .xlsx into RStudio - I'm not sure why RStudio can't see the file. Am I specifying the path for read_excel() wrong? Any ideas? Pretty new at R.

Thanks!

Windows 10 (64-bit) Version 0.99.491 & Version 0.99.840 read.xl 0.1.0

getwd() [1] "C:/Users/user/Documents/Work" read_excel(system.file("C:/Users/user/Documents/Work/Data.xlsx")) Error: '' does not exist in current working directory ('C:/Users/user/Documents/Work')

like image 911
Justin Lim Avatar asked May 07 '26 02:05

Justin Lim


2 Answers

The results of the system.file command are probably returning a blank character "":

system.file("C:/Users/user/Documents/Work/Data.xlsx")  
[1] ""

I'm not sure why this is the case. Instead, just try specifying the full path within the excel_sheets function, i.e.,

read_excel("C:/Users/user/Documents/Work/Data.xlsx")
like image 80
Nathan Avatar answered May 09 '26 14:05

Nathan


I like to use paste0 function:

read_excel(paste0(getwd(), "/Data.xlsx"))
like image 38
Emma Avatar answered May 09 '26 15:05

Emma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!