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

Zero column data frames make addDataFrame fail #31

Closed
GoogleCodeExporter opened this issue Jul 19, 2015 · 3 comments
Closed

Zero column data frames make addDataFrame fail #31

GoogleCodeExporter opened this issue Jul 19, 2015 · 3 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
wb <- createWorkbook()
sheet <- createSheet(wb)
dfr <- data.frame(x = 1:5)[,FALSE] #Data frame with some rows, no columns.
addDataFrame(dfr, sheet)
## Error in .jcall(cellBlock$ref, "V", setDataMethod, as.integer(j - 1L),  : 
##   java.lang.ArrayIndexOutOfBoundsException: 1

What is the expected output? What do you see instead?
I expected addDataFrame to gracefully decline to add any content to the 
worksheet rather than throwing an error.

What version of the product are you using? On what operating system?
xlsx version '0.5.5'.

Please provide any additional information below.

The problem is caused by line 46 (depending upon how you count them):

    for (j in 1:ncol(x)) {

When x has zero columns, then 1:ncol(x) is c(1, 0), not an empty vector.

To fix the problem, change the line to:

    for(j in seq_along(x)) {


Original issue reported on code.google.com by richiero...@gmail.com on 30 Jan 2014 at 11:32

@GoogleCodeExporter
Copy link
Author

A quick search through the source of xlsx reveals that the file write.xlsx.R 
contains two more instances of 1:ncol, and five instances of 1:nrow.  I haven't 
checked to see if these cause problems, but it is safer to replaces them with 
calls to seq_len or seq_along.

Original comment by richiero...@gmail.com on 30 Jan 2014 at 11:35

@GoogleCodeExporter
Copy link
Author

thanks.  looking at it.

Original comment by adrian.d...@gmail.com on 13 Feb 2014 at 4:12

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

Fixed in trunk. 

Original comment by adrian.d...@gmail.com on 13 Feb 2014 at 6:43

  • Changed state: Done

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

No branches or pull requests

1 participant