SymbolixAU / jsonify

R package to convert R objects to JSON
https://symbolixau.github.io/jsonify/
Other
67 stars 10 forks source link

AsIs matrix-column of data.frame #42

Closed SymbolixAU closed 5 years ago

SymbolixAU commented 5 years ago
df <- data.frame( id = 1:2, mat = I(matrix(1:4, ncol = 2)))
df
  id mat.1 mat.2
1  1     1     3
2  2     2     4

str( df )
'data.frame':   2 obs. of  2 variables:
 $ id : int  1 2
 $ mat: 'AsIs' int [1:2, 1:2] 1 2 3 4

jsonify::to_json( df )
[{"id":1,"mat":1},{"id":2,"mat":2}]

The 2nd column of the matrix is ignored.

dcooley commented 5 years ago
df <- structure(list(fill_colour = structure(c(68, 49, 53, 253, 1, 
104, 183, 231, 84, 142, 121, 37, 255, 255, 255, 255), .Dim = c(4L, 
4L)), geometry = c(1, 2, -5, 0.3), lat = 1:4, lon = c(1, 2, -5, 
0.3)), class = "data.frame", row.names = c(NA, 4L))

This needs to work 'by-row', on a single vector here