Skip to contents

mergeDataPackages() merges MR1 data packages of several campaigns, e.g. read with readDataPackageFromZenodo() or created with createDataPackage(), into one data package. Each resource (echo_data, protocol_data, blind_times, sunrise_sunset, site_data) holds the rows of all campaigns, with the campaign in the first column, campaignID.

IDs such as echo and protocolID are only unique within a campaign, so they are kept as they are, and the primary and foreign keys of the merged package include campaignID. Columns that are missing in some packages are filled with NA.

The merged package keeps the metadata of each campaign in the property mr1dp:campaigns (title, version, DOI, owner, licences, embargo, period, site, suggested citation and Zenodo information), and lists the packages as sources. Contributors, licences and keywords are combined; contributors with the same ORCID (or name) are listed once. Use citeDataPackages() to cite the merged data.

A merged package is meant for analysis, not for publication: validateDataPackage() checks packages of single campaigns. Write it to disk with frictionless::write_package() if needed.

Usage

mergeDataPackages(packages)

Arguments

packages

list of MR1 data packages (class mr1dp or datapackage), each with a different campaignID.

Value

A data package (class mr1dp and datapackage) with the merged resources as data frames. Read a resource with frictionless::read_resource().

Author

Birgen Haest

Examples

# \donttest{
# Create two data packages of the example data (two days, as if they were
# two campaigns)
# ===========================================================================
dbData = readRDS(system.file("extdata",
  "CH_Sempach_2024_SEP24_25_DataExtract.rds",
  package = "birdscanR"
))
metadata = yaml::read_yaml(system.file("extdata", "dataPackage",
  "metadataTemplate.yaml",
  package = "birdscanR"
))
day1 = createDataPackage(dbData,
  metadata = utils::modifyList(metadata, list(campaignID = "CH_Sempach_2024_day1")),
  timeRangeTargetTZ = c("2024-09-24 00:00", "2024-09-24 23:59")
)
day2 = createDataPackage(dbData,
  metadata = utils::modifyList(metadata, list(campaignID = "CH_Sempach_2024_day2")),
  timeRangeTargetTZ = c("2024-09-25 00:00", "2024-09-25 23:59")
)

# Merge them
# ===========================================================================
merged = mergeDataPackages(list(day1, day2))
#> Warning: `resources()` was deprecated in frictionless 1.3.0.
#> ℹ Please use `resource_names()` instead.
#> ℹ The deprecated feature was likely used in the base package.
#>   Please report the issue to the authors.
#> Warning: `get_schema()` was deprecated in frictionless 1.3.0.
#> ℹ Please use `schema()` instead.
#> ℹ The deprecated feature was likely used in the birdscanR package.
#>   Please report the issue at
#>   <https://github.com/BirdScanCommunity/birdscanR/issues>.
echoData = frictionless::read_resource(merged, "echo_data")
table(echoData$campaignID)
#> 
#> CH_Sempach_2024_day1 CH_Sempach_2024_day2 
#>                 8141                 5830 
# }