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

initial_rowno in expand_cat_json() is wrong if by=F, JSON empty, and na.rm = T #9

Open
berg-michael opened this issue Jul 14, 2021 · 0 comments

Comments

@berg-michael
Copy link

Hi,

Not sure if this is a bug or intended behavior. The JSON in the second row of the input datatable is empty. If I expand the JSON with by = F and na.rm = T, the initial_rowno variable for rows 3 and 4 of the output is 2, when it should be 3. If I set na.rm = F, it becomes 3.

Obviously this issue can be avoided entirely by setting na.rm = F. Maybe it should be obvious to me why this behavior occurs, but it confused me so I thought I'd bring it up.

Thanks for all your work on this package, by the way!

patterns <- data.table::data.table(state_fips = c(1,2,3),
                                   cat_origin = c('{"a": "2", "b": "3"}',
                                                  '{}',
                                                  '{"a": "4", "b": "5"}'))
> patterns
   state_fips           cat_origin
1:          1 {"a": "2", "b": "3"}
2:          2                   {}
3:          3 {"a": "4", "b": "5"}
> 
expand_cat_json(
  patterns,
  'cat_origin',
  'index',
  by = F,
  na.rm = T
)
   initial_rowno cat_origin index
1:             1          2     a
2:             1          3     b
3:             2          4     a
4:             2          5     b
expand_cat_json(
  patterns,
  'cat_origin',
  'index',
  by = F,
  na.rm = F
)
   initial_rowno cat_origin index
1:             1          2     a
2:             1          3     b
3:             3          4     a
4:             3          5     b
@berg-michael berg-michael changed the title initial_rowno in expand_cat_json() is wrong if by=F, JSON empty, and na.rm = F initial_rowno in expand_cat_json() is wrong if by=F, JSON empty, and na.rm = T Jul 14, 2021
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

1 participant