-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed m(), now aw() exists Typos
- Loading branch information
Showing
23 changed files
with
358 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
^data-raw$ | ||
^README\.Rmd$ | ||
^\.github$ | ||
^checks$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
*.bak | ||
*.tmp | ||
*.bib.sav | ||
checks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(aw) | ||
export(icsColor) | ||
export(m) | ||
export(minSearch) | ||
export(minsForChemistry) | ||
importFrom(Rdpack,reprompt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#' IUPAC Standard atomic weights of the elements | ||
#' | ||
#' A data set containing the standard atomic weights of the elements as | ||
#' recommended by the [International Union of Pure and Applied Chemistry | ||
#' (IUPAC)](https://www.iupac.org) and [Commission on Isotopic Abundances and | ||
#' Atomic Weights (CIAAW)](https://www.ciaaw.org). | ||
#' | ||
#' This is table 1 of \insertCite{Prohaska2022}{georefdatar}. The (foot)notes in | ||
#' the table have been collected in a new column (Notes) and their abbreviations | ||
#' resolved into sentences. | ||
#' | ||
#' | ||
#' @format A data frame with `r nrow(IUPAC_StdAW)` rows and the following | ||
#' `r ncol(IUPAC_StdAW)` columns:\cr | ||
#' \describe{ | ||
#' \item{Element}{Element's name} | ||
#' \item{Symbol}{Element's symbol} | ||
#' \item{Atomic number}{Element's atomic number. Elements are listed in | ||
#' increasing atomic number} | ||
#' \item{stdAW::Value}{Values of standard atomic weights are given as single | ||
#' values with uncertainties (column stdAW::Uncertainty) or as intervals.} | ||
#' \item{stdAW::Uncertainty}{of the Value of the standard atomic weight} | ||
#' \item{abrStdAW::Value}{Abridged atomic weights quoted to five significant | ||
#' figures. Unless such precision cannot be attained due to the variability of | ||
#' isotopic composition in normal materials or due to the limitations of the | ||
#' measurement capability.} | ||
#' \item{abrStdAW::±}{A +/− value as a simplified measure of the reliability of | ||
#' the abridged values.} | ||
#' \item{Note}{The collected footnotes of the table. Notes are resolved to the | ||
#' sentences associated with them. If there is more than one note, the notes are | ||
#' separated by an newline (`\n`).} | ||
#' } | ||
#' | ||
#' @seealso [aw()] for a function to get the standard atomic weights of the elements found in this table by their symbols | ||
#' @seealso [IUPAC periodic table of elements](https://iupac.org/what-we-do/periodic-table-of-elements/) online | ||
#' @seealso [CIAAW](https://www.ciaaw.org/) also a periodic table of elements online | ||
#' @seealso [CIAAW standard atomic weights](https://www.ciaaw.org/atomic-weights.htm) online | ||
#' | ||
#' @references \insertCite{Prohaska2022}{georefdatar} | ||
#' | ||
#' | ||
#' @importFrom Rdpack reprompt | ||
"IUPAC_StdAW" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#' Get the atomic weight of an element | ||
#' | ||
#' @param sym symbol of the element as a string | ||
#' @param dataSource the data source for the atomic weight, either `IUPAC` | ||
#' (default) or `PubChem`. This is case insensitive ("IUPAC" is the same as | ||
#' e.g. "IuPaC") | ||
#' | ||
#' @return Atomic weight of element with the given symbol | ||
#' | ||
#' @seealso [IUPAC_StdAW] for the table of standard atomic weights | ||
#' by IUPAC and [pte] for a full periodic table of elements | ||
#' | ||
#' @export | ||
#' | ||
#' @examples | ||
#' aw('H') | ||
#' aw('H')*2+aw('O') | ||
#' | ||
#' aw('Li', dataSource= "pubchem") | ||
#' | ||
aw <- function(sym, dataSource="IUPAC") { | ||
dataSource <-toupper(dataSource) | ||
stopifnot("Unknown data source!"= dataSource %in% c("IUPAC", "PUBCHEM")) | ||
|
||
if (dataSource == "PUBCHEM") | ||
return(georefdatar::pte[georefdatar::pte$Symbol==sym, ]$AtomicMass) | ||
|
||
georefdatar::IUPAC_StdAW[georefdatar::IUPAC_StdAW$Symbol== sym, ]$`abrStdAW::Value` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
110 changes: 110 additions & 0 deletions
110
data-raw/IUPAC__Standard_atomic_weights_of_the_elements.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
## code to prepare `DATASET` dataset goes here | ||
|
||
t <- readxl::read_excel('data-raw/IUPAC__2021__Standard_atomic_weights_of_the_elements.xlsx', sheet = 'Table 1') | ||
|
||
# Rename columns | ||
## There are two rows, that will be squeezed into one | ||
## Standard Atomic Weight => prefix: "stdAW::" | ||
## Abridged Standard Atomic Weight => prefix "abrStdAW::" | ||
t[1,4] <- "stdAW::Value" | ||
t[1,5] <- 'stdAW::Uncertainty' | ||
t[1,7] <- "abrStdAW::Value" | ||
t[1,8] <- "abrStdAW::±" | ||
|
||
# remove line two, after column renaming not needed any more | ||
t <- t[-2,] | ||
|
||
# Read ourselves and skip first row. So the upper changes in the column values | ||
# will be the column names | ||
t <- readxl::read_excel(writexl::write_xlsx(t), skip = 1) | ||
|
||
|
||
|
||
# convert to numeric | ||
|
||
## Standard atomic weight | ||
## there is non-breaking space in here | ||
## tools::showNonASCII(t$`stdAW::Uncertainty`) | ||
## U+00A0 c2 a0 NO-BREAK SPACE | ||
|
||
### stdAW::Value: We can't convert this vector fully since there are ranges | ||
### but we can clean it from the non-breaking spaces | ||
t$`stdAW::Value` <- gsub("(\\s|\u00A0)", "", t$`stdAW::Value`) | ||
|
||
### stdAW::Uncertainty: This vector can be cleaned fully | ||
t$`stdAW::Uncertainty` <- as.numeric(gsub("(\\s|\u00A0)", "", t$`stdAW::Uncertainty`)) | ||
|
||
## abridged standard atomic weight | ||
## Convert this fully to numeric values | ||
t$`abrStdAW::Value` <- as.numeric(t$`abrStdAW::Value`) | ||
t$`abrStdAW::±` <- as.numeric(t$`abrStdAW::±`) | ||
|
||
## check for non numeric | ||
stopifnot(hularr::which.nonnumeric(t$`abrStdAW::Value`) == 0) | ||
stopifnot(hularr::which.nonnumeric(t$`abrStdAW::±`) == 0 ) | ||
stopifnot(hularr::which.nonnumeric(t$`stdAW::Uncertainty`) == 0) | ||
|
||
# notes column | ||
# Will be the summary of the (foot) notes | ||
t$Note <- NA | ||
|
||
|
||
# Elements having an asterisk in the end, those are the elements with footnote | ||
# a) in table 1. They are marked with an asterisk in the excel file to not let | ||
# the element name end with an 'a'. | ||
# This should be 38 elements | ||
fna <- which(grepl("\\*$", t$Element)) | ||
stopifnot(length(fna) == 38) | ||
# Remove the * and leave a note | ||
t$Element[fna] <- gsub("\\*$", "", t$Element[fna]) | ||
t$Note[fna] <- 'a' | ||
|
||
# Capitalize elements | ||
# t$Element <- unlist(lapply(t$Element, function(x) { | ||
# substr(x,1,1) <- toupper(substr(x, 1, 1)) | ||
# x | ||
# })) | ||
|
||
|
||
|
||
# check elements | ||
## Al and Cs will show up, since there is a difference in the writing | ||
t[which(!(toupper(t$Element) %in% toupper(pte$Name))), "Element"] | ||
|
||
## Check symbols | ||
t[-which(t$Symbol %in% pte$Symbol), "Symbol"] | ||
|
||
|
||
# Combine Foot-note and Note | ||
combineLists <- function(l1, l2) { | ||
unlist( | ||
lapply(seq_along(l1), function(i) { | ||
if (is.na(l1[i]) & is.na(l2[i])) | ||
return(NA) | ||
|
||
if (is.na(l1[i]) & !is.na(l2[i])) | ||
return(l2[i]) | ||
|
||
if (!is.na(l1[i]) & is.na(l2[i])) | ||
return(l1[i]) | ||
|
||
return(paste(l1[i], l2[i])) | ||
}) | ||
) | ||
} | ||
xx <- combineLists(t$Note, t$`Foot-note`) | ||
|
||
# resolve footnotes | ||
## import foot note texts | ||
fnotes <- readxl::read_excel('data-raw/IUPAC__2021__Standard_atomic_weights_of_the_elements.xlsx', sheet = 'Tab1_footnotes') | ||
# Turn this into a names list | ||
fnotes <- with(fnotes, setNames(Text, Footnote)) | ||
# replace notes by their texts | ||
t$Note <- unlist(lapply(strsplit(xx, "\\s"), function(y) paste(fnotes[y], collapse = "\n"))) | ||
t$Note <- gsub("NA", NA, t$Note) | ||
# remove foot-note, now resolved in Notes | ||
t$`Foot-note` <- NULL | ||
|
||
# we finished | ||
IUPAC_StdAW <- as.data.frame(t) | ||
usethis::use_data(IUPAC_StdAW, overwrite = TRUE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.