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

Push re-encoding of xls path into XlsWorkBook constructor #674

Merged
merged 1 commit into from
Jan 3, 2022

Conversation

jennybc
Copy link
Member

@jennybc jennybc commented Jan 3, 2022

I'm making this PR to restore symmetry of read_xls_() and read_xlsx_(). I want their signature and body to be the same (for eventual de-deduplication). The symmetry was lost at the time of the Rcpp --> cpp11 conversion (33c79a5).

General recap of this path handling:

  • User's path needs to be normalized to expand, e.g., a leading ~/. At least for xls, we need to do this (see xls path containing the "~" shortcut can't be read #498).
  • As of R 3.5, normalizePath() (path.expand(), really) returns UTF-8 encoded output, even if the input was not UTF-8.
  • Once we adopted cpp11, it also does automatic conversion to UTF-8 for strings.
  • This is fine for xlsx because we ultimately open the file with R (see zip_buffer() in R/xlsx-zip.R).
  • For xls, we need to re-encode to the native encoding before we pass the path to libxls, which uses fopen().

Relevant previous history:

@jennybc
Copy link
Member Author

jennybc commented Jan 3, 2022

@gaborcsardi Will you just provide a quick look? I've tried to summarize how we got here and I'm quite confident this is reasonable.

@gaborcsardi
Copy link
Member

For xls, we need to re-encode to the native encoding before we pass the path to libxls, which uses fopen().

FWIW this will not work on Unicode paths if they cannot be represented in the single-byte native encoding, and _wfopen() should be used instead on Windows. But you probably already know this, and I understand that you might not want to fix this in this PR.

Looks good otherwise.

@jennybc
Copy link
Member Author

jennybc commented Jan 3, 2022

But you probably already know this, and I understand that you might not want to fix this in this PR.

I consider this a libxls problem. I guess I could open an issue or even a PR there, but I think I've got higher priority stuff to work on in readxl.

@jennybc jennybc merged commit 4540dff into main Jan 3, 2022
@jennybc jennybc deleted the refactor-xls-path branch January 3, 2022 16:42
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

Successfully merging this pull request may close these issues.

2 participants