Adds a Tabular Data Resource to a Data
Package.
The resource will be a Tabular Data Resource.
The resource name can only contain lowercase alphanumeric characters plus
.
, -
and _
.
Arguments
- package
List describing a Data Package, created with
read_package()
orcreate_package()
.- resource_name
Name of the Data Resource.
- data
Data to attach, either a data frame or path(s) to CSV file(s):
Data frame: attached to the resource as
data
and written to a CSV file when usingwrite_package()
.One or more paths to CSV file(s) as a character (vector): added to the resource as
path
. The last file will be read withreadr::read_delim()
to create or compare withschema
and to setformat
,mediatype
andencoding
. The other files are ignored, but are expected to have the same structure and properties.
- schema
Either a list, or path or URL to a JSON file describing a Table Schema for the
data
. If not provided, one will be created usingcreate_schema()
.- 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 CSV dialect, so read functions know how to read the file(s).- ...
Additional metadata properties to add to the resource, e.g.
title = "My title", validated = FALSE
. These are not verified against specifications and are ignored byread_resource()
. The following properties are automatically set and can't be provided with...
:name
,data
,path
,schema
,profile
,format
,mediatype
,encoding
anddialect
.
See also
Other edit functions:
get_schema()
,
remove_resource()
Examples
# Load the example Data Package
package <- example_package
# List resources
resources(package)
#> [1] "deployments" "observations" "media"
# Create a data frame
df <- data.frame(
multimedia_id = c(
"aed5fa71-3ed4-4284-a6ba-3550d1a4de8d",
"da81a501-8236-4cbd-aa95-4bc4b10a05df"
),
x = c(718, 748),
y = c(860, 900)
)
# Add resource "positions" to the Data Package, from the data frame
package <- add_resource(package, "positions", data = df)
# Add resource "positions_2" to the Data Package, with user-defined schema
# and title
my_schema <- create_schema(df)
package <- add_resource(
package,
"positions_2",
data = df,
schema = my_schema,
title = "Positions"
)
# Add resource "observations_2" to the Data Package, from CSV file paths
path_1 <- system.file("extdata", "observations_1.csv", package = "frictionless")
path_2 <- system.file("extdata", "observations_2.csv", package = "frictionless")
package <- add_resource(package, "observations_2", data = c(path_1, path_2))
# List resources ("positions", "positions_2", "observations_2" added)
resources(package)
#> [1] "deployments" "observations" "media" "positions"
#> [5] "positions_2" "observations_2"