Here is my minimal reproducible example:
temp = list()
temp$rows$`1`$rows$name <- "rows"
temp$rows$`1`$rows$`1`$cells$name <- "cells"
temp$rows$`2`$rows$name <- "rows"
temp$rows$`2`$rows$`2`$cells$name <- "cells"
Current output:
$rows
$rows$`1`
$rows$`1`$rows
$rows$`1`$rows$name
[1] "rows"
$rows$`1`$rows$`1`
$rows$`1`$rows$`1`$cells
$rows$`1`$rows$`1`$cells$name
[1] "cells"
$rows$`2`
$rows$`2`$rows
$rows$`2`$rows$name
[1] "rows"
$rows$`2`$rows$`2`
$rows$`2`$rows$`2`$cells
$rows$`2`$rows$`2`$cells$name
[1] "cells"
I wonder is there a programmatic way to replace $1
to [[1]]
and $2
to [[2]]
in this list? So make the output look like this because this is an important step to make arrays when convert a list to JSON.
$rows
$rows[[1]]
$rows[[1]]$rows
$rows[[1]]$rows$name
[1] "rows"
$rows[[1]]$rows[[1]]
$rows[[1]]$rows[[1]]$cells
$rows[[1]]$rows[[1]]$cells$name
[1] "cells"
$rows[[2]]
$rows[[2]]$rows
$rows[[2]]$rows$name
[1] "rows"
$rows[[2]]$rows[[2]]
$rows[[2]]$rows[[2]]$cells
$rows[[2]]$rows[[2]]$cells$name
[1] "cells"
Here is what I tried but not working in the right way:
lapply(temp$rows$
1, unname)
Thanks!