make_json {ltertools} | R Documentation |
Make a JSON File with Specified Contents
Description
Creates a JSON (JavaScript Object Notation) file containing the specified name/value pairs. These files are hugely flexible and interpretable by a wide variety of coding languages and thus extremely useful in many contexts. This function is meant to assist those who wish to use JSON files to store user-specific information (e.g., email addresses, absolute file paths, etc.) in collaborative contexts.
Usage
make_json(x = NULL, file = NULL, git_ignore = FALSE)
Arguments
x |
(character) named vector from which to generate JSON content. Vector elements become JSON values and the vector element names become JSON names. A named vector can be created like so: |
file |
(character) name of JSON file to create with contents provided to |
git_ignore |
(logical) whether to add the file name (defined in |
Value
Nothing. Called for side-effects (i.e., creating JSON file)
Examples
# Create contents
my_info <- c("data_path" = "Users/me/documents/my_project/data")
# Generate a local folder for exporting
temp_folder <- tempdir()
# Create a JSON with those contents
make_json(x = my_info, file = file.path(temp_folder, "user.json"), git_ignore = FALSE)
# Read it back in
(user_info <- RJSONIO::fromJSON(content = file.path(temp_folder, "user.json")))