This function adds a resource to a package and ensures that the data conforms to the schema defined for that resource. The schema is used to validate and potentially modify the data frame before adding it to the package.
Usage
add_gldp_resource(
package,
resource_name,
data,
cast_type = FALSE,
replace = FALSE,
delim = ","
)
Arguments
- package
The package object to which the resource will be added.
- resource_name
A character string specifying the name of the resource. This name is used to locate the schema file.
- data
A data frame containing the data to be added as a resource. The data frame will be adjusted according to the schema.
- cast_type
A logical value indicating whether the data frame should be cast to the types specified in the schema. Defaults to
FALSE
.- replace
If
TRUE
, the added resource will replace an existing resource with the same name.- delim
Single character used to separate the fields in the CSV file(s), e.g.
\t
for tab delimited file. Will be set asdelimiter
in the resource Table Dialect, so read functions . know how to read the file(s).
Details
The schema for the resource is fetched from a JSON file located in a specified directory.
The function adjusts the data frame according to the schema's fieldsMatch
property:
"equal"
: The data frame must have exactly the same fields as defined in the schema."subset"
: The data frame must have at least the fields defined in the schema, but may have additional fields. Fields not present in the schema are added to the schema."superset"
: The data frame may have fields not present in the schema, but must include all fields defined in the schema."partial"
: The data frame must have at least one field defined in the schema.
Examples
if (FALSE) { # \dontrun{
my_package <- some_package_function()
my_data <- data.frame(a = 1:5, b = letters[1:5])
updated_package <- add_gldp_resource(my_package, "my_resource", my_data)
} # }