R/toJSONarray.R

Defines functions toJSONarray

# This function was copied directly from D3network package:
# https://github.com/christophergandrud/d3Network/blob/cc224daa983e59dbe743c18e1ccb621bdd0ce509/R/utils.R

toJSONarray <- function(dtf){
  clnms <- colnames(dtf)
  
  name.value <- function(i){
    quote <- '';
    if(!is(dtf[, i],"numeric") && !is(dtf[, i], "integer")){
      quote <- '"';
    }
    paste('"', i, '" : ', quote, dtf[,i], quote, sep='')
  }
  objs <- apply(sapply(clnms, name.value), 1, function(x){paste(x, 
                                                                collapse=', ')})
  objs <- paste('{', objs, '}')
  
  res <- paste('[', paste(objs, collapse=', '), ']')
  
  return(res)
}

Try the qgraph package in your browser

Any scripts or data that you put into this service are public.

qgraph documentation built on Nov. 3, 2023, 5:07 p.m.