edit_attribute: Edit a single attribute

View source: R/edit_attribute.R

edit_attributeR Documentation

Edit a single attribute

Description

This function edits the slots of a single attribute in an existing list of attributes for a data object.

Usage

edit_attribute(
  attribute,
  attributeName = NULL,
  attributeLabel = NULL,
  attributeDefinition = NULL,
  domain = NULL,
  measurementScale = NULL,
  unit = NULL,
  numberType = NULL,
  definition = NULL,
  formatString = NULL,
  missingValueCode = NULL,
  missingValueCodeExplanation = NULL
)

Arguments

attribute

(attribute) The attribute in the the attributeList of a data object.

attributeName

(character) The new name to give to the attribute.

attributeLabel

(character) The new label to give to the attribute.

attributeDefinition

(character) The new attributeDefinition to give to the attribute.

domain

(character) The new domain to give to the attribute.

measurementScale

(character) The new measurementScale to give to the attribute.

unit

(character) The new unit (for numericDomain) to give to the attribute.

numberType

(character) The new numberType (for numericDomain) to give to the attribute.

definition

(character) The new definition (for textDomain) to give to the attribute.

formatString

(character) The new formatString (for dateTime) to give to the attribute.

missingValueCode

(character) The new missing value code to give to the attribute.

missingValueCodeExplanation

(character) The new missing value code explanation to give to the attribute.

Details

This function can only be used on attributes entirely defined within the 'attributes' slot of attributeList; it cannot be used to edit the factors table of an enumeratedDomain.

In cases with very large attribute lists, use arcticdatautils::which_in_eml() first to locate the attribute index number in the attributeList.

Value

(attribute) The modified attribute.

Examples

## Not run: 
cn <- dataone::CNode('PROD')
mn <- dataone::getMNode(cn, 'urn:node:ARCTIC')
doc <- EML::read_eml(rawToChar(dataone::getObject(mn, "doi:10.18739/A23W02")))
new_attribute <- edit_attribute(doc$dataset$dataTable[[1]]$attributeList$attribute[[1]],
                                attributeName = "new name")
doc$dataset$dataTable[[1]]$attributeList$attribute[[1]] <- new_attribute

# Change an attribute's measurementScale from ratio to nominal
# (requires updating domain to textDomain or enumeratedDomain, setting unit and numberType
# to NA and adding a setting definition
new_attribute <- edit_attribute(doc$dataset$dataTable[[1]]$attributeList$attribute[[1]],
                                domain = "textDomain", measurementScale = "nominal", unit = NA,
                                numberType = NA, definition = 'new definition')
doc$dataset$dataTable[[1]]$attributeList$attribute[[1]] <- new_attribute
EML::eml_validate(doc) # validating complex EML changes is usually a good idea

# Add the same missing value codes to all attributes for a data object
new_attributes <- lapply(doc$dataset$dataTable[[1]]$attributeList$attribute, edit_attribute,
                         missingValueCode = "NA", missingValueCodeExplanation = "data unavailable")
doc$dataset$dataTable[[1]]$attributeList$attribute <- new_attributes

## End(Not run)

NCEAS/datamgmt documentation built on June 5, 2023, 6:14 a.m.