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

Named colClasses doesn't work #200

Open
Stikus opened this issue Jul 5, 2022 · 2 comments
Open

Named colClasses doesn't work #200

Stikus opened this issue Jul 5, 2022 · 2 comments

Comments

@Stikus
Copy link

Stikus commented Jul 5, 2022

According to documentation:
https://www.rdocumentation.org/packages/xlsx/versions/0.6.5/topics/read.xlsx
image

Here is my simple test xlsx file:
image

  • Without colClasses:
> META <- xlsx::read.xlsx('1.xlsx', sheetIndex = 1)
> str(META)
'data.frame':	1 obs. of  3 variables:
 $ A: chr "ABC"
 $ B: Date, format: "1970-01-01"
 $ C: num 2000
  • With all classes described:
> META <- xlsx::read.xlsx('1.xlsx', sheetIndex = 1, colClasses = c(A = "character", B = "Date", C = 'character'))
> str(META)
'data.frame':	1 obs. of  3 variables:
 $ A: chr "ABC"
 $ B: Date, format: "1970-01-01"
 $ C: chr "0000"
  • Looks like all good, but if you remove first class F = "character":
> META <- xlsx::read.xlsx('1.xlsx', sheetIndex = 1, colClasses = c(B = "Date", C = 'character'))
> str(META)
'data.frame':	1 obs. of  3 variables:
 $ A: Date, format: NA
 $ B: chr "0"
 $ C: num 2000
Warning message:
In as.POSIXlt.Date(x) : NAs introduced by coercion

colClasses doesn't respect names - only position in vector.

@colearendt
Copy link
Owner

Thanks for the great reprex! This should make it much easier to isolate and fix (although I haven't looked to see how complex a fix is).

Just for future reference on other projects, the reprex package can provide even more simple "copy and use" examples. It's a bit tricky with the xlsx package, but the way we do it in our tests is often to write out the file in question to a temp file and then import it.

@Stikus
Copy link
Author

Stikus commented Feb 16, 2024

@colearendt Hello, I see that xlsx package doesn't receive any updated for long time, do you have any fix for this problem?

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