Edit custom units
EML has a set list of units that can be added to an EML file. These can be seen by using the following code:
If you have units that are not in the standard EML unit list, you will need to build a custom unit list. A unit typically consists of the following fields:
- id: The
unit id
(ids are camelCased) - unitType: The
unitType
(runView(standardUnits$unitTypes)
to see standardunitType
s) - parentSI: The
parentSI
unit (e.g. for kilometerparentSI
= “meter”) - multiplierToSI: Multiplier to the
parentSI
unit (e.g. for kilometermultiplierToSI
= 1000) - name: Unit abbreviation (e.g. for kilometer
name
= “km”) - description: Text defining the unit (e.g. for kilometer
description
= “1000 meters”)
To manually generate the custom units list, create a dataframe with the fields mentioned above. An example is provided below that can be used as a template:
custom_units <- data.frame(
id = c('partsPerThousand', 'decibar', 'wattsPerSquareMeter', 'micromolesPerGram', 'practicalSalinityUnit'),
unitType = c('dimensionless', 'pressure', 'power', 'amountOfSubstanceWeight', 'dimensionless'),
parentSI = c(NA, 'pascal', 'watt', 'molesPerKilogram', NA),
multiplierToSI = c(NA, '10000', '1', '1000000000', NA),
abbreviation = c('ppt', 'decibar', 'W/m^2', 'umol/g', 'PSU'),
description = c('parts per thousand', 'decibar', 'watts per square meter', 'micro moles per gram', 'used to describe the concentration of dissolved salts in water, the UNESCO Practical Salinity Scale of 1978 (PSS78) defines salinity in terms of a conductivity ratio'))
Using EML::get_unit_id
for custom units will also generate valid EML unit ids.
Custom units are then added to additionalMetadata
using the following command:
If units that should be standardUnit
are added as customUnit
, you can use the following code to fix this issue:
# add standard unit
doc$dataset$dataTable[[i]]$attributeList$attribute[[i]]$measurementScale$ratio$unit$standardUnit <- "your standard unit"
# get rid of custom unit
doc$dataset$dataTable[[i]]$attributeList$attribute[[i]]$measurementScale$ratio$unit$customUnit <- NULL
If you want to find all of the positions of a certain custom unit that should be standard, try this code: