add_metadata: helper function for package to set attributes of a dataset

View source: R/add_metadata.R

add_metadataR Documentation

helper function for package to set attributes of a dataset

Description

This can be used annually to update some datasets in a package. It just makes it easier to set a few metadata attributes similarly for a number of data elements, for example, to add new or update existing attributes.

Usage

add_metadata(x, metadata)

Arguments

x

dataset (or any object) whose metadata you want to update or create

metadata

must be a named list, so that the function can do this for each i: attr(x, which=names(metadata)[i]) <- metadata[[i]]

Value

returns x but with new or altered attributes

Examples

  x <- data.frame(a=1:10,b=1001:1010)
  metadata <- list(
  census_version = 2020,
  acs_version = '2016-2020',
  acs_releasedate = '3/17/2022',
  ejscreen_version = '2.1',
  ejscreen_releasedate = 'October 2022',
  ejscreen_pkg_data = 'bg22'
  )
  x <- add_metadata(x, metadata)
  attributes(x)
  x <- add_metadata(x, list(status='final'))
  attr(x,'status')

ejanalysis/ejscreen documentation built on April 2, 2024, 10:15 a.m.