1

I believe a switch to OneDrive is causing some issues in various packages in R due to spaces being incorporated into the file path name. One shown below is the readxl package. Is there a way to get the package to read the spaces in the file path names? Or is it something other than the spaces that I might have overlooked?

Installation and the loading of the library work fine. However, when trying to import an excel file, it only works if I put the file in a location without spaces in the file path. I need the file to be in OneDrive so that it will be backed up.


install.packages("readxl")
library("readxl")

TRENDS_2020 <- read_excel("C:\\Users\\name03\\OneDrive - Specific Details Here (ABC)\\Backup_12_22_2020\\WQ_ALL_FINAL_WEBSITE_PIVOT_TRENDS_2020.xlsx")

I get the following error when running that:

Error in utils::unzip(zip_path, list = TRUE) : 
  zip file 'C:\Users\name03\OneDrive - Specific Details Here (ABC)\Backup_12_22_2020\TRENDS_2020.xlsx' cannot be opened

The following does work for the same file that I copy and pasted into my C drive:

TRENDS_2020 <-read_excel("C:\\TRENDS_2020.xlsx")
Scott R
  • 133
  • 2
  • 13
  • Probably not to do with spaces. Do you have the file open in Excel? That will cause an error. – SamR May 09 '22 at 17:07
  • I don't think the issue is the spaces--I would expect a "file not found" error if spaces were the issue. OneDrive often causes permissions issues with files. Perhaps you can `file.copy` it in and out of OneDrive. Another thing to check with MS office files is to make sure they are not open in any office applications, as that can lock the file. – Gregor Thomas May 09 '22 at 17:09
  • 1
    You could confirm the space issue by creating a local folder with a space in the name (not in OneDrive) and testing it there. – Gregor Thomas May 09 '22 at 17:10
  • If this is really due to the spaces, you can try the **shortPathName** function. – Stéphane Laurent May 09 '22 at 17:33

1 Answers1

0

Zip {utils}

treated as if passed to system, if the filepaths contain spaces they must be quoted e.g. by shQuote.

Statistical Data Analysis ETH Zurich

kraggle
  • 196
  • 2
  • 9