Skip to content

Unexpected result with toJSON(..., byrow=TRUE) on empty data frame  #22

Description

@daniel-ohayon

Hi,
I noticed the following behaviour with toJSON:

cat(toJSON(data.frame(logical(0)), byrow=TRUE), '\n')
[
 [
 null 
],
[] 
] 

When I would instead expect [] (?)

I believe the problem comes from this line

  if(byrow) {
      tmp = lapply(1:nrow(x), function(i) { row = as.list(x[i, ])
                                           if(colNames)
                                             row                                             
                                           else
                                             unname(row)
                                         })

where 1:nrow(x) should be replaced by seq_len(nrow(x)) (because 1:0 is actually the vector c(1,0)).

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions