Title: | Create Lightweight Schema.org Descriptions of Data |
---|---|
Description: | The goal of 'dataspice' is to make it easier for researchers to create basic, lightweight, and concise metadata files for their datasets. These basic files can then be used to make useful information available during analysis, create a helpful dataset "README" webpage, and produce more complex metadata formats to aid dataset discovery. Metadata fields are based on the 'Schema.org' and 'Ecological Metadata Language' standards. |
Authors: | Carl Boettiger [aut] (https://github.com/cboettig), Scott Chamberlain [aut] (https://github.com/sckott), Auriel Fournier [aut] (https://github.com/aurielfournier), Kelly Hondula [aut] (https://github.com/khondula), Anna Krystalli [aut] (https://github.com/annakrystalli), Bryce Mecum [aut, cre] (https://github.com/amoeba), Maëlle Salmon [aut] (https://github.com/maelle), Kate Webbink [aut] (https://github.com/magpiedin), Kara Woo [aut] (https://github.com/karawoo), Irene Steves [ctb] (https://github.com/isteves) |
Maintainer: | Bryce Mecum <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.1.0 |
Built: | 2024-10-28 06:22:41 UTC |
Source: | https://github.com/ropensci/dataspice |
Convert a list object to JSON-LD
as_jsonld( x, context = "http://schema.org", pretty = TRUE, auto_unbox = TRUE, ... )
as_jsonld( x, context = "http://schema.org", pretty = TRUE, auto_unbox = TRUE, ... )
x |
the object to be encoded. |
context |
JSON-LD context; "http://schema.org". |
pretty |
Whether or not to prettify output. See
|
auto_unbox |
Whether or not to automatically unbox output. See
|
... |
Other arguments to be passed to
|
Build a dataspice site
build_site( path = file.path("data", "metadata", "dataspice.json"), template_path = system.file("template.html5", package = "dataspice"), out_path = file.path("docs", "index.html") )
build_site( path = file.path("data", "metadata", "dataspice.json"), template_path = system.file("template.html5", package = "dataspice"), out_path = file.path("docs", "index.html") )
path |
(character) Path to a JSON+LD file with dataspice metadata |
template_path |
(character) Optional. Path to a template for
|
out_path |
(character) Optional. Path to write the site's |
Nothing. Creates/overwrites docs/index.html
## Not run: # Create JSON+LD from a set of metadata templates json <- write_json(biblio, access, attributes, creators) build_site(json) ## End(Not run)
## Not run: # Create JSON+LD from a set of metadata templates json <- write_json(biblio, access, attributes, creators) build_site(json) ## End(Not run)
metadata
subdirectoryPut metadata templates within a metadata
subdirectory
create_spice(dir = "data")
create_spice(dir = "data")
dir |
Directory containing data, within which a |
## Not run: create_spice() # Create templates from the data in a folder other than `data` create_spice("my_data") ## End(Not run)
## Not run: create_spice() # Create templates from the data in a folder other than `data` create_spice("my_data") ## End(Not run)
Crosswalk a term
crosswalk(doc, term)
crosswalk(doc, term)
doc |
(list) A |
term |
(character) The term to crosswalk. |
(list) The result of the crosswalk. May be an empty list
on
failure.
Crosswalk a Schema.org/creator
crosswalk_creator(creator)
crosswalk_creator(creator)
creator |
(list) A creator |
A quick and dirty crosswalk of an unknown date(time) input to EML that really
only works for ISO8601 input. All other formats will fail and be returned
as-is as a calendarDate
. From there the user will need to do a conversion
themselves.
crosswalk_datetime(input)
crosswalk_datetime(input)
input |
(character) Some unknown date(time) input |
(list) A list
with members calendarDate
and time
. time
will
be NULL
if parsing fails or if the time string inside input
isn't
ISO8601
Crosswalk a Schema.org/distribution
crosswalk_distribution(distribution)
crosswalk_distribution(distribution)
distribution |
(list) A distribution |
Crosswalk a Schema.org/Organization
crosswalk_Organization(creator)
crosswalk_Organization(creator)
creator |
(list) A creator |
as_eml
Crosswalk a Schema.org/PersonCrosswalk functions for as_eml
Crosswalk a Schema.org/Person
crosswalk_Person(creator)
crosswalk_Person(creator)
creator |
(list) A creator |
dataspice
variables to EMLSee set_attributes
for more information on what must be
filled out after this is run in order to get a valid EML attributeList
.
crosswalk_variables(spice)
crosswalk_variables(spice)
spice |
(list) Your |
(data.frame) A partial EML attributes table
## Not run: # Load an example dataspice JSON that comes installed with the package spice <- system.file( "examples", "annual-escapement.json", package = "dataspice") # Convert it to EML (notice the warning) eml_doc <- suppressWarnings({spice_to_eml(spice)}) attributes <- crosswalk_variables(spice) # Now fill in the attributes data.frame. See `EML::set_attributes`. # And last, set the attributes on our EML document eml_doc$dataset$dataTable[[1]]$attributeList <- EML::set_attributes(attributes) ## End(Not run)
## Not run: # Load an example dataspice JSON that comes installed with the package spice <- system.file( "examples", "annual-escapement.json", package = "dataspice") # Convert it to EML (notice the warning) eml_doc <- suppressWarnings({spice_to_eml(spice)}) attributes <- crosswalk_variables(spice) # Now fill in the attributes data.frame. See `EML::set_attributes`. # And last, set the attributes on our EML document eml_doc$dataset$dataTable[[1]]$attributeList <- EML::set_attributes(attributes) ## End(Not run)
Launch Shiny app for editing individual dataspice
metadata tables. Use
edit_*()
where *
is one of the four dataspice
metadata tables
attributes
, biblio
, access
or creators
.
edit_access(metadata_dir = file.path("data", "metadata"))
edit_access(metadata_dir = file.path("data", "metadata"))
metadata_dir |
the directory containing the |
## Not run: edit_attributes() edit_biblio() edit_access() edit_creators() # Specifying a different dataspice metadata directory edit_attributes(metadata_dir = "analysis/data/metadata/")) ## End(Not run)
## Not run: edit_attributes() edit_biblio() edit_access() edit_creators() # Specifying a different dataspice metadata directory edit_attributes(metadata_dir = "analysis/data/metadata/")) ## End(Not run)
Launch Shiny app for editing individual dataspice
metadata tables. Use
edit_*()
where *
is one of the four dataspice
metadata tables
attributes
, biblio
, access
or creators
.
edit_attributes(metadata_dir = file.path("data", "metadata"))
edit_attributes(metadata_dir = file.path("data", "metadata"))
metadata_dir |
the directory containing the |
## Not run: edit_attributes() edit_biblio() edit_access() edit_creators() # Specifying a different dataspice metadata directory edit_attributes(metadata_dir = "analysis/data/metadata/")) ## End(Not run)
## Not run: edit_attributes() edit_biblio() edit_access() edit_creators() # Specifying a different dataspice metadata directory edit_attributes(metadata_dir = "analysis/data/metadata/")) ## End(Not run)
Launch Shiny app for editing individual dataspice
metadata tables. Use
edit_*()
where *
is one of the four dataspice
metadata tables
attributes
, biblio
, access
or creators
.
edit_biblio(metadata_dir = file.path("data", "metadata"))
edit_biblio(metadata_dir = file.path("data", "metadata"))
metadata_dir |
the directory containing the |
## Not run: edit_attributes() edit_biblio() edit_access() edit_creators() # Specifying a different dataspice metadata directory edit_attributes(metadata_dir = "analysis/data/metadata/")) ## End(Not run)
## Not run: edit_attributes() edit_biblio() edit_access() edit_creators() # Specifying a different dataspice metadata directory edit_attributes(metadata_dir = "analysis/data/metadata/")) ## End(Not run)
Launch Shiny app for editing individual dataspice
metadata tables. Use
edit_*()
where *
is one of the four dataspice
metadata tables
attributes
, biblio
, access
or creators
.
edit_creators(metadata_dir = file.path("data", "metadata"))
edit_creators(metadata_dir = file.path("data", "metadata"))
metadata_dir |
the directory containing the |
## Not run: edit_attributes() edit_biblio() edit_access() edit_creators() # Specifying a different dataspice metadata directory edit_attributes(metadata_dir = "analysis/data/metadata/")) ## End(Not run)
## Not run: edit_attributes() edit_biblio() edit_access() edit_creators() # Specifying a different dataspice metadata directory edit_attributes(metadata_dir = "analysis/data/metadata/")) ## End(Not run)
Create dataspice metadata tables from EML
eml_to_spice(eml, path = NULL)
eml_to_spice(eml, path = NULL)
eml |
(emld) An EML object |
path |
(character) Folder path for saving the tables to disk |
A list with names attributes
, access
, biblio
, and creators
.
Optionally, if path
is specified, saves the four tables as CSV
files.
## Not run: # First, load up an example EML record library(EML) eml_path <- system.file( file.path("example-dataset", "broodTable_metadata.xml"), package = "dataspice") eml <- read_eml(eml_path) # Generate the four dataspice tables my_spice <- eml_to_spice(eml) # Or save them as a file # Generate the four dataspice tables eml_to_spice(eml, ".") ## End(Not run)
## Not run: # First, load up an example EML record library(EML) eml_path <- system.file( file.path("example-dataset", "broodTable_metadata.xml"), package = "dataspice") eml <- read_eml(eml_path) # Generate the four dataspice tables my_spice <- eml_to_spice(eml) # Or save them as a file # Generate the four dataspice tables eml_to_spice(eml, ".") ## End(Not run)
Return EML access in the dataspice access.csv format.
es_access(eml, path = NULL)
es_access(eml, path = NULL)
eml |
(emld) an EML object |
path |
(character) folder path for saving the table to disk |
Return EML attributes in the dataspice attributes.csv format.
es_attributes(eml, path = NULL)
es_attributes(eml, path = NULL)
eml |
(emld) an EML object |
path |
(character) folder path for saving the table to disk |
Return EML biblio in the dataspice biblio.csv format.
es_biblio(eml, path = NULL)
es_biblio(eml, path = NULL)
eml |
(emld) an EML object |
path |
(character) folder path for saving the table to disk |
Return EML creators in the dataspice creators.csv format.
es_creators(eml, path = NULL)
es_creators(eml, path = NULL)
eml |
(emld) an EML object |
path |
(character) folder path for saving the table to disk |
Convert JSONLD to a list suitable for Mustache templating
jsonld_to_mustache(path)
jsonld_to_mustache(path)
path |
(character) Path to file on disk to convert |
(list) Mustache-appropriate list
Parse spatialCoverage$geo$box section for use in a Leaflet map
parse_GeoShape_box(box)
parse_GeoShape_box(box)
box |
(list) spatialCoverage$geo$box section of the JSONLD |
(list) Template-specific variables for Leaflet
Parse spatialCoverage section for use in a Leaflet map
parse_spatialCoverage(spatialCoverage)
parse_spatialCoverage(spatialCoverage)
spatialCoverage |
(list) spatialCoverage section of the JSONLD |
(list) Template-specific variables for Leaflet
Extract fileNames
from data file(s) and add them to access.csv
. The
helper validate_file_paths
can be used to create vectors of
valid file paths that can be checked and then passed as data_path
argument
to prep_access
.
prep_access( data_path = "data", access_path = file.path("data", "metadata", "access.csv"), ... )
prep_access( data_path = "data", access_path = file.path("data", "metadata", "access.csv"), ... )
data_path |
character vector of either:
|
access_path |
path to the |
... |
parameters passed to |
Updates access.csv
and writes to access_path
.
## Not run: # First create the metadata tempaltes create_spice() # Then begin filling them in from your data files prep_access() ## End(Not run)
## Not run: # First create the metadata tempaltes create_spice() # Then begin filling them in from your data files prep_access() ## End(Not run)
Extract variableNames
from data file(s) and add them to attributes.csv
.
The helper validate_file_paths
can be used to create vectors of
valid file paths that can be checked and then passed as data_path
argument
to prep_attributes
.
prep_attributes( data_path = "data", attributes_path = file.path("data", "metadata", "attributes.csv"), ... )
prep_attributes( data_path = "data", attributes_path = file.path("data", "metadata", "attributes.csv"), ... )
data_path |
character vector of either:
|
attributes_path |
path to the |
... |
parameters passed to |
prep_attributes()
updates the attributes.csv
and writes to
attributes_path
.
## Not run: create_spice() # extract attributes from all `csv`, `tsv`, `rds` files in the data folder # (non recursive) prep_attributes() # recursive prep_attributes(recursive = TRUE) # extract attributes from a single file using file path data_path <- system.file("example-dataset","BroodTables.csv", package = "dataspice") prep_attributes(data_path) # extract attributes from a single file by file path pattern matching data_path <- system.file("example-dataset", package = "dataspice") prep_attributes(data_path, pattern = "StockInfo") # extract from a folder using folder path data_path <- system.file("example-dataset", package = "dataspice") prep_attributes(data_path) ## End(Not run)
## Not run: create_spice() # extract attributes from all `csv`, `tsv`, `rds` files in the data folder # (non recursive) prep_attributes() # recursive prep_attributes(recursive = TRUE) # extract attributes from a single file using file path data_path <- system.file("example-dataset","BroodTables.csv", package = "dataspice") prep_attributes(data_path) # extract attributes from a single file by file path pattern matching data_path <- system.file("example-dataset", package = "dataspice") prep_attributes(data_path, pattern = "StockInfo") # extract from a folder using folder path data_path <- system.file("example-dataset", package = "dataspice") prep_attributes(data_path) ## End(Not run)
Serve site
serve_site(path = "docs")
serve_site(path = "docs")
path |
(character) Optional. Directory to serve. Defaults to
|
Nothing.
## Not run: # Build your site json <- write_json(biblio, access, attributes, creators) build_site(json) # Serve it serve_site() ## End(Not run)
## Not run: # Build your site json <- write_json(biblio, access, attributes, creators) build_site(json) # Serve it serve_site() ## End(Not run)
dataspice
metadata to EMLPerforms an (imperfect) conversion of dataspice
metadata to EML. It's
very likely you will get validation errors and need to fix them afterwards
but spice_to_eml
is a good way to a richer metadata schema (EML) when
you're already using dataspice
but need a richer metadata schema.
spice_to_eml(spice = file.path("data", "metadata", "dataspice.json"))
spice_to_eml(spice = file.path("data", "metadata", "dataspice.json"))
spice |
(list) Your |
(emld) The crosswalked emld
object
# Load an example dataspice JSON that comes installed with the package spice <- system.file( "examples", "annual-escapement.json", package = "dataspice" ) # And crosswalk it to EML spice_to_eml(spice) # We can also create dataspice metadata from scratch and crosswalk it to EML myspice <- list( name = "My example spice", creator = "Me", contact = "Me" ) spice_to_eml(myspice)
# Load an example dataspice JSON that comes installed with the package spice <- system.file( "examples", "annual-escapement.json", package = "dataspice" ) # And crosswalk it to EML spice_to_eml(spice) # We can also create dataspice metadata from scratch and crosswalk it to EML myspice <- list( name = "My example spice", creator = "Me", contact = "Me" ) spice_to_eml(myspice)
Validate access.csv
validate_access(access)
validate_access(access)
access |
(data.frame) A |
Nothing. Side-effect: Can stop
execution if validation fails.
Validate attributes.csv
validate_attributes(attributes)
validate_attributes(attributes)
attributes |
(data.frame) A |
Nothing. Side-effect: Can stop
execution if validation fails.
Validate biblio.csv
validate_biblio(biblio)
validate_biblio(biblio)
biblio |
(data.frame) A |
Nothing. Side-effect: Can stop
execution if validation fails.
Validate creators.csv
validate_creators(creators)
validate_creators(creators)
creators |
(data.frame) A |
Nothing. Side-effect: Can stop
execution if validation fails.
Helper function to return a set of file paths for use in other functions
validate_file_paths(data_path = "data", ...)
validate_file_paths(data_path = "data", ...)
data_path |
character vector of either:
|
... |
parameters passed to |
One or more data file paths
## Not run: # Assuming some data files in "./data" my_files <- validate_file_paths() # If your data files are in `another_folder` my_files <- validate_file_paths("another_folder") ## End(Not run)
## Not run: # Assuming some data files in "./data" my_files <- validate_file_paths() # If your data files are in `another_folder` my_files <- validate_file_paths("another_folder") ## End(Not run)
Write a list out as object to JSON-LD
write_jsonld( x, path, context = "http://schema.org", pretty = TRUE, auto_unbox = TRUE, ... )
write_jsonld( x, path, context = "http://schema.org", pretty = TRUE, auto_unbox = TRUE, ... )
x |
an object to be serialized to JSON |
path |
file on disk |
context |
JSON-LD context; "http://schema.org" |
pretty |
adds indentation whitespace to JSON output. Can be TRUE/FALSE or a number specifying the number of spaces to indent. See |
auto_unbox |
automatically |
... |
additional conversion arguments, see also toJSON or fromJSON |
Write out your metadata as a dataspice JSON-LD document
write_spice(path = file.path("data", "metadata"), ...)
write_spice(path = file.path("data", "metadata"), ...)
path |
location of metadata files |
... |
additional arguments to |
A JSON-LD file at the path specified
## Not run: # First create your metadata templates create_spice() # Then fill in the template files however you like # Then write out your dataspice file write_spice() ## End(Not run)
## Not run: # First create your metadata templates create_spice() # Then fill in the template files however you like # Then write out your dataspice file write_spice() ## End(Not run)