-
Notifications
You must be signed in to change notification settings - Fork 76
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
saveWorkbook() does not drop an error when overwriting an open existing file #176
Comments
Interesting, I also have the latest code v4.2.3, but am running on MacOS using Microsoft Excel for Mac Version 16.48 and everything works just fine. I typical have my excel file open, then rerun the R script which overwrites the file without any issues even though it is open. |
Thank you cwolcott. Do I understand correctly that the file is overwritten while being open, without warning/error messages and, although being open, the file is updated? |
@pakom correct. The file is overwritten even though it is open, without any warning/error message and although being opened the file is updated. I just added returnValue = TRUE TRUE was returned, meaning success. Documentation - saveWorkbook Is there any additional log files I should look at for more details? |
@cwolcott That's interesting, on Windows it behaves differently. I added
I suppose that this is because of the operating system. UNIX-like systems allow overwriting opened files. I don't have Linux installed on this machine, but I suppose it will behave the same as on MacOS. |
@pakom, So now you can determine if the process of writing the xlsx file was successful or not with the returnValue=TRUE. I agree that the OS is allowing/disallowing the overwriting of open files. On macOS I locked the file and am receiving the following warning:
So in your case if the process fails what do you want to do? Trying saving it again, but with a timestamp so it is unique or stop processing and log the issue? General info - Overwriting an Open File in Windows |
@cwolcott Thank you for following this. I just tested it on Linux, it does completely different thing compared to Windows and MacOS when adding Why I'm asking all this is because I have a function which drops a custom error message like this:
It was catching the original warning message thrown from the |
Wow, very interesting to know. So I am new in R, and you have passed my level of knowledge. Is the basic question why is the saveWorkbook no longer throwing an error that can be caught? Good luck! I will be watching the thread to learn more. |
@cwolcott Thank you, although I don't perceive myself so knowledgeable in R. The basic question now evolved into "Why |
I just looked at the code and indeed there has been a change in the following line in version 4.2.2: Line 122 in fade982
This changed happened to fix this issue : #71 To answer your questions:
One way to solve is to keep saving the warning message(4.2.2 behavior) and at the same time to send the warnings to the standard output (before 4.2.2 behavior). @ycphs , what's your opinion on this? |
I really like the explanation in issue #71. Thank you for the teaching moment. I will add the following to my code for the time being, since I haven't thought through if I need to handle this in more detail.
|
This issue is stale because it has been open 365 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
I am not sure that this is bug or intended behavior. I did not use the
openxlsx
package for a while and few days ago I needed it for a small task (I have updated to v4.2.3). Consider this minimal example:It all works fine, the MS Excel file is overwritten, as required. However, I remember that when using the package several months ago, the function dropped an error if the MS Excel file exists and it's open. With the latest version, if the file is open in MS Excel, no error is thrown and the file is (of course) not overwritten. Is this desired behavior?
I tried to add a check if the file is open using the proposed solutions here. without any success. Using the first solution corrupted the file, using the second did nothing.
Any recommendations on how to get the error back?
I am using Windows 10 and don't know what is the behavior in other operating systems.
Thank you in advance,
pakom
The text was updated successfully, but these errors were encountered: