Skip to content

Commit

Permalink
recursively convert named vectors to lists; ref #10
Browse files Browse the repository at this point in the history
  • Loading branch information
timelyportfolio committed Dec 1, 2015
1 parent fe62e17 commit 40b7018
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions R/jsonedit.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,19 @@ jsonedit <- function(
# with named vectors
# convert named vectors to list
# see https://github.com/timelyportfolio/listviewer/issues/10
# note the conversion does not occur
# if a named vector is nested in a list or data.frame
if(
!inherits(listdata,"list") &&
is.null(dim(listdata)) &&
!is.null(names(listdata))
){
listdata <- as.list(listdata)
named_vec2list <- function(listx){
if(
!inherits(listx,"list") &&
is.null(dim(listx)) &&
!is.null(names(listx))
){
listx <- as.list(listx)
}
return(listx)
}

if(inherits(listdata,"list")){
listdata <- rapply(listdata,named_vec2list,how="list")
}

# forward options using x
Expand Down

0 comments on commit 40b7018

Please sign in to comment.