R/mod_json.R

Defines functions mod_json

Documented in mod_json

#' Converts a data frame to json minus the square brackets on the ends
#'
#' @param x dataframe intended for json conversoin
#' @param type (string) one of "fromJSON" or "toJSON"

mod_json <- function(x, type) {

  if (type == "toJSON") {
    x <- x %>% jsonlite::toJSON()
    x <- substr(x, 2, nchar(x) - 1)
    return(x)
  }

  if (type == "fromJSON") {
    x <- jsonlite::fromJSON(rawToChar(x$content))
    return(x)
  }

}

Try the RobinHood package in your browser

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

RobinHood documentation built on March 1, 2021, 5:08 p.m.