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

Conversion to dataframe fails with tibbles #121

Open
IdoBar opened this issue Mar 6, 2019 · 4 comments
Open

Conversion to dataframe fails with tibbles #121

IdoBar opened this issue Mar 6, 2019 · 4 comments

Comments

@IdoBar
Copy link

IdoBar commented Mar 6, 2019

When using write.xlsx() on a tibble at the end of a dplyr-style pipe, a very cryptic error appears:

Error in .jcall(cell, "V", "setCellValue", value) : 
  method setCellValue with signature ([D)V not found

Apparently it's because the data is not considered as a dataframe and is not converted to one on the fly.
In addition, the dataframe isn't returned, so it can't be used to assign back the values or continue the pipe (like readr::write_csv() does).
See my suggested PR #120

@colearendt
Copy link
Owner

Related to #73 and #100 . Thanks for the PR!

@IdoBar
Copy link
Author

IdoBar commented Mar 9, 2019

After reading the other relevant issues and doing some testing I updated the PR to check if data is not a data.frame OR is a tibble to convert to a data.frame

@colearendt
Copy link
Owner

Impeccably timed feedback from a user in the community:

There's a very subtle problem in the function 'write.xlsx' in the package 'xlsx'

drawn to my attention by Art Stock (cc'ed here).

Executing write.xlsx(x, .......),
If the argument 'x' inherits class 'data.frame' but also inherits another class 'foo',

then the lines

if(!is.data.frame(x))
x <- as.data.frame(x)

will not change the class of 'x'. Later in the code, the internal generic cbind() is called, and this could be dispatched to cbind.foo() instead of the intended cbind.data.frame().

My package 'spatstat' produces objects of class c("fv", "data.frame") and there is a method cbind.fv() which is invoked in this context and causes an error.

May I suggest you just omit the line
if(!is.data.frame(x))

Perhaps we should just remove the check and always run as.data.frame on the inputs. Would that solve your case @IdoBar ?

I think we should definitely hem this in with test cases for various types of input and what types of output we would expect. It will be important to discern whether removing the check completely would cause breaking changes for vector inputs, for instance.

@khughitt
Copy link

khughitt commented Nov 8, 2019

I'm all for automatically calling as.data.frame() on inputs. If there is a situation where the user is trying to call write.xlsx() on something that cannot be coerced to a dataframe, I think they have a bigger problem on their hands.

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

3 participants