0

R script doesn't seem to be closing a file properly, leaving it locked for editing by users. File and script are on a shared drive, script is run manually.

Note: I didn't write the script, and the person who did is no longer with the company, and that user is the one whose name is in the "locked for editing by" message. I'm trying to track down the issue for another manager.

I've not done much coding in R, in python the pd.read_excel function has built-in context, so I don't know how to force close a file programmatically in R. Any help would be appreciated.

Relevant code snippet:

Data <- read_excel("//foo/bar.xlsx", 
                   sheet = "baz", col_types = c("skip", 
                                                         "numeric", "text", "date", "text", 
                                                         "numeric", "numeric", "numeric", "text", "text", "text", 
                                                         "numeric", "text", "text", "date", 
                                                         "text", "numeric", "date", "numeric", 
                                                         "text", "text", "text", "text", "text", 
                                                         "text","text"))
G. Anderson
  • 5,815
  • 2
  • 14
  • 21
  • Are you using read_excel from the `readxl` package? If so this might be of some help to you https://github.com/tidyverse/readxl/issues/300 – abcalphabet Sep 26 '18 at 15:26
  • 1
    The `read_excel` file should close the file as soon as it's done running. Are you sure it's the R code that's locking the file? Without a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) it's going to be difficult to help you. (I can't replicate the error just using `read_excel` – MrFlick Sep 26 '18 at 15:27
  • @abcalphabet, that looks very similar, we _are_ using the tidyverse readxl package, but the version is `1.1.0`, and it looks like that issue was fixed in `0.1.1.9000` if I'm reading correctly. Unless the issue has recurred, I'm telling the manager to check on the windows permissions side. Thanks! – G. Anderson Sep 26 '18 at 16:13

1 Answers1

0

Sorry to waste everyone's time, turns out the commenters so far were on the right track. The new user who got the old user's laptop rebooted, and the file unlocked, so it looks like a microsoft issue.

Thanks for the quick, helpful responses.

G. Anderson
  • 5,815
  • 2
  • 14
  • 21