#' List the fields in a Data Resource
#'
#' @param x object for which to get the field names. This can either be a Data
#' Resource or Table Schema.
#'
#' @return
#' Returns a character vector with the fields in the Data Resource.
#'
#' @export
dpfieldnames <- function(x) {
UseMethod("dpfieldnames")
}
#' @export
dpfieldnames.tableschema <- function(x) {
# TODO: convert to dpproperty
fields <- x$fields
if (is.null(fields)) stop("Fields are missing from Table Schema of Data Resource.")
sapply(fields, function(f) {
if (!exists("name", f)) stop("Field without name.")
f$name
})
}
#' @export
dpfieldnames.dataresource <- function(x) {
schema <- dpschema(x)
if (is.null(schema)) stop("Data Resource does not have a schema property.")
dpfieldnames(schema)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.