Skip to content

Instantly share code, notes, and snippets.

@randyzwitch
Last active August 29, 2015 14:01
Show Gist options
  • Save randyzwitch/34a793f7c06c4a103fc2 to your computer and use it in GitHub Desktop.
Save randyzwitch/34a793f7c06c4a103fc2 to your computer and use it in GitHub Desktop.
JSON in R using paste
#"metrics" would be a user input into a function arguments
metrics <- c("a", "b", "c")
#Loop over the metrics list, appending proper curly braces
metrics_conv <- lapply(metrics, function(x) paste('{"id":', '"', x, '"', '}', sep=""))
#Collapse the list into a proper comma separated string
metrics_final <- paste(metrics_conv, collapse=", ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment