Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrupting files on windows Readr 2.0 #1263

Closed
l-gorman opened this issue Aug 5, 2021 · 2 comments
Closed

Corrupting files on windows Readr 2.0 #1263

l-gorman opened this issue Aug 5, 2021 · 2 comments

Comments

@l-gorman
Copy link

l-gorman commented Aug 5, 2021

Hi all!

I recently upgraded to readr version 2.0. When I did this, I ran in to some problems with older scripts. I worked out, the problem was that if I read a csv using readr::read_csv and then rewrote the object to a file using readr::write_csv, the file would become corrupted in some way.

In particualr, when writing the file, I would get the error:

Cannot open the file for writing

When I went to try and reopen the file in Excel, it would open without a problem, but when trying to modify and save the file, I would receive the error:

Can not be accessed. The file may be corrupted located on a server that is not responding

This is an example of code that would produce this type of error:

# The process was simply
df<-data.frame(read_csv("filename.csv",na=c('n/a','<NA>','NA')))

write_csv(df,"filename.csv")

I am using windows 10 (64-bit) and R version 4.1.0.

In the end I switched back to version 1.4 and everything works again.

Let me know if you need any more details :)

(By the way this is not a complaint at all, I love this package, just thought I would point this out in case it helpful!)

@jimhester
Copy link
Collaborator

With lazy reading a file handle remains open until the whole file has been read. On Windows if any process has an open file handle to a file it is locked and nothing else can write to it.

Use lazy=FALSE when reading the file, and then no file handle will remain open and what you are trying to do will work.

@l-gorman
Copy link
Author

l-gorman commented Aug 5, 2021

@jimhester Thanks so much! That's really good to know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants