diff --git a/DESCRIPTION b/DESCRIPTION index d674006..da07feb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,12 +1,12 @@ Package: isotopia Type: Package Title: Work with isotopic data in R -Version: 0.2 +Version: 0.3 Date: 2014-04-05 Author: Sebastian Kopf Maintainer: Sebastian Kopf Description: R interface for working with isotopic data (abundances, ratios, - delta values, etc.). + fractionation factors, delta values, etc.). License: GPL-3 LazyLoad: yes Roxygen: list(wrap = FALSE) diff --git a/R/arithmetic.R b/R/arithmetic.R index 3d10946..4f2d6e3 100644 --- a/R/arithmetic.R +++ b/R/arithmetic.R @@ -95,8 +95,7 @@ setMethod("+", signature(e1 = "Abundance", e2 = "Abundance"), function(e1, e2) { #' @usage delta +- delta #' @details #' \code{delta+-delta} is a shorthand for calculating the isotopic mass balance of -#' two \code{\link{delta}} objects, see \code{\link{mass_balance}} for details, -#' will use the global \code{\link{exact_mass_balance}} setting for the calculation +#' two \code{\link{delta}} objects, see \code{\link{mass_balance}} for details #' @name arithmetic #' @rdname arithmetic NULL @@ -329,9 +328,9 @@ setMethod("/", signature(e1 = "FractionationFactor", e2 = "FractionationFactor") #' @usage delta / delta #' @details -#' \code{delta/delta} creates an \code{\link{alpha}} fractionation factor object that +#' \code{delta/delta} creates an \code{\link{fractionation_factor}} object that #' describes the fractionation factor between the two compounds, requires the reference -#' name of the two delta values to be identical. This is a shorthand for the \link{frac_factor} function. +#' name of the two delta values to be identical. This is a shorthand for the \link{to_ff} function. #' @name arithmetic #' @rdname arithmetic NULL diff --git a/R/attribs.R b/R/attribs.R index a3b1578..eabc795 100644 --- a/R/attribs.R +++ b/R/attribs.R @@ -154,23 +154,23 @@ setMethod("weight", signature("Isoval", "numeric"), function(iso, weight) { #' primitive data value(s). #' #' @param notation specifiy which notation to return the value in (default is the notation -#' that hte object is in) +#' that the object is in) #' @return In the case of a single isotope object (Isoval), returns the numeric -#' vector of raw values stored in the object (same as \code{\link{as.numeric}}). +#' vector of raw values stored in the object (same as \code{\link[base]{as.numeric}}). #' In the case of an isotope system (Isosys), #' returns the data frame underlying the object with all its isotope value #' objects also replaced with their numeric raw values. To just get the data #' frame but keep the isotope values intact, use \code{\link{as.data.frame}} instead. -#' @seealso \code{\link{as.numeric}}, \code{\link{as.data.frame}}, \code{\link[base]{as.data.frame}} (base method) +#' @seealso \code{\link[base]{as.numeric}}, \code{\link{as.data.frame}}, \code{\link[base]{as.data.frame}} (base method) #' @family data type attributes #' @method get_value #' @export -setGeneric("get_value", function(iso, notation = "raw") standardGeneric("get_value")) +setGeneric("get_value", function(iso, notation = iso@notation) standardGeneric("get_value")) #' @method get_value #' @export -setMethod("get_value", "ANY", function(iso, notation = "raw") stop("get_value not defined for objects of class ", class(iso))) -setMethod("get_value", "numeric", function(iso, notation = "raw") iso) # allow this for simplicity so this is similiar to as_numeric +setMethod("get_value", "ANY", function(iso, notation) stop("get_value not defined for objects of class ", class(iso))) +setMethod("get_value", "numeric", function(iso, notation = NULL) iso) # allow this for simplicity so this is similiar to as_numeric setMethod("get_value", "Isoval", function(iso, notation = iso@notation) as.numeric(switch_notation(iso, notation))) setMethod("get_value", "Isosys", function(iso, notation = NULL) { data.frame(lapply(iso, diff --git a/R/conversion.R b/R/conversion.R index 88424b5..9b24feb 100644 --- a/R/conversion.R +++ b/R/conversion.R @@ -137,7 +137,7 @@ setMethod("to_ratio", "Delta", function(iso) { else if (length(stds) > 1) message("No reference ratio registered with the delta value, tried to find one from the registered standards but found multiple, delta: ", get_label(iso)) else if (length(stds) == 1) { - message("Successfully found a matching standard to convert delta value without registered reference: ", get_label(stds[[1]]), ": ", get_value(stds[[1]])) + message("Successfully found a registered standard to convert delta value: ", get_label(stds[[1]]), ": ", signif(get_value(stds[[1]]), 4)) iso@ref_ratio <- get_value(stds[[1]]) } } @@ -200,6 +200,7 @@ setMethod("to_abundance", "Intensities", function(iso) to_abundance(to_ratio(iso # delta to abundance setMethod("to_abundance", "Delta", function(iso) { + # FIXME: add warning for isotope systems with more than one ratio? r <- to_ratio(iso) to_abundance(r) }) @@ -213,7 +214,7 @@ setMethod("to_abundance", "Delta", function(iso) { #' #' @usage to_ff(iso1, iso2) #' @details -#' The \code{frac_factor(...)} function calculates the fractionation factor between two isotope data objects +#' The \code{to_ff(...)} function calculates the fractionation factor between two isotope data objects #' (for example two \code{\link{delta}} values, two \code{\link{ratio}}, or two \code{\link{ff}}). #' All calculatinos are only permissible if the isotope values have matching #' attributes and fractionation factors will be returend in the default notation @@ -324,6 +325,12 @@ setMethod("to_delta", signature(iso = "FractionationFactor", ref_ratio = "Ratio" # ratio to delta ========= +# ratio to delta (with numeric ref ratio) +setMethod("to_delta", signature("Ratio", "missing"), function(iso, ref_ratio) { + stop("Can't convert from a ratio to a delta value without a reference ratio.") +}) + + # ratio to delta (with numeric ref ratio) setMethod("to_delta", signature("Ratio", "numeric"), function(iso, ref_ratio) { to_delta(iso, update_iso(ratio(ref_ratio), list(isoname = iso@isoname, major = iso@isoname))) diff --git a/R/initialization.R b/R/initialization.R index 822c51a..2baf2b6 100644 --- a/R/initialization.R +++ b/R/initialization.R @@ -54,12 +54,12 @@ ab <- abundance #' Fractionation factor #' -#' FIXME, change description -#' Generate a fractionation factor (alpha value = ratio of two isotope ratios) object. See \link{isotopia} for general information on initializing -#' and converting isotope data objects. -#' Fractionation factors can be easily converted from values in one notation to values in +#' Generate a fractionation factor object. Can be initialized in \code{alpha} and +#' \code{epsilon} notation. Fractionation factors can be easily converted from values in one notation to values in #' another notation by using \code{\link{switch_notation}}. #' +#' See \link{isotopia} for general information on initializing +#' and converting to other isotope data objects. #' The \code{ff} function is a shorthand for \code{fractionation_factor} but otherwise identical. #' #' @param ... - numeric vectors (can be named) to turn into fractionation factors @@ -90,8 +90,7 @@ ff <- fractionation_factor #' another notation by using \code{\link{switch_notation}}. #' #' For mass balance calculations with delta values, simply add the appropriate weights (if different from -#' the default) and use \code{delta(...) + delta(...)}. Use \code{\link{exact_mass_balance}(TRUE/FALSE)} -#' to adjust how these are calculated. +#' the default) and use \code{delta(...) + delta(...)}. #' #' @param ... - numeric vectors (can be named) to turn into delta values #' @param major - name of the major isotope in the isotope system [optional] diff --git a/R/operations.R b/R/operations.R index 26667a3..f39c3ba 100644 --- a/R/operations.R +++ b/R/operations.R @@ -9,26 +9,26 @@ NULL #' is also implemented with an \code{\link{arithmetic}} shorthand. #' #' @param ... - any number of weighted isotope value objects (have to be all either abundance or delta) -#' @param exact - whether to calculate mass balance of delta values exactly (default FALSE), -#' use exact_mass_balance to set this paramter globally +#' @param exact - whether to calculate mass balance of delta values exactly (default FALSE), not +#' fully implemented yet #' @return weighted abundance or delta value object that represents the combination of the parameters #' @family operations #' @method mass_balance #' @export -setGeneric("mass_balance", function(iso, iso2, ..., exact = exact_mass_balance()) standardGeneric("mass_balance")) +setGeneric("mass_balance", function(iso, iso2, ..., exact = get_iso_opts("exact_mass_balance")) standardGeneric("mass_balance")) #' @method mass_balance #' @export -setMethod("mass_balance", "ANY", function(iso, iso2, ..., exact = exact_mass_balance()) stop("mass_balance not defined for objects of class ", class(iso), ", ", class(iso2))) +setMethod("mass_balance", "ANY", function(iso, iso2, ..., exact = get_iso_opts("exact_mass_balance")) stop("mass_balance not defined for objects of class ", class(iso), ", ", class(iso2))) -setMethod("mass_balance", signature("Abundance", "Abundance"), function(iso, iso2, ..., exact = exact_mass_balance()) { +setMethod("mass_balance", signature("Abundance", "Abundance"), function(iso, iso2, ..., exact = get_iso_opts("exact_mass_balance")) { # consider implementing a performance optimized version for many additions all <- c(list(iso2), list(...)) for (i in all) iso = iso + i iso }) -setMethod("mass_balance", signature("Delta", "Delta"), function(iso, iso2, ..., exact = exact_mass_balance()) { +setMethod("mass_balance", signature("Delta", "Delta"), function(iso, iso2, ..., exact = get_iso_opts("exact_mass_balance")) { if (exact) stop("not implemented yet!") # should be implemented here rather than in the operators @@ -38,15 +38,15 @@ setMethod("mass_balance", signature("Delta", "Delta"), function(iso, iso2, ..., iso }) -setMethod("mass_balance", signature("Deltas", "Deltas"), function(iso, iso2, ..., exact = exact_mass_balance()) { +setMethod("mass_balance", signature("Deltas", "Deltas"), function(iso, iso2, ..., exact = get_iso_opts("exact_mass_balance")) { stop("not implemented yet") }) #' Fractionate an isotopic value #' -#' This function calculates the outcome of isotopic fractionation by a \code{\link{fractionation_fractor}} +#' This function calculates the outcome of isotopic fractionation by a \code{\link{fractionation_factor}} #' and can be applied to \code{\link{ratio}} data, \code{\link{delta}} values or other -#' \code{\link{fractionation_fractor}} objects. +#' \code{\link{fractionation_factor}} objects. #' @param frac the fractionation factor \code{\link{ff}} used to fractionate the isotope value #' @param iso the isotope object to fractionate #' @return an object of the same type as \code{iso} diff --git a/R/utils.R b/R/utils.R index 14c2127..c811a35 100644 --- a/R/utils.R +++ b/R/utils.R @@ -20,7 +20,7 @@ drop_list <- function(l) { #' #' This small utility function is just a convenient wrapper for running #' isotope calculations silently without outputting any of the warnings or -#' messages (it uses \link{suppressMessages} and \link{suppressWarnings} +#' messages (it uses \link[base]{suppressMessages} and \link[base]{suppressWarnings} #' internally) that might occur. Use with care to suppress warnings, you #' might end up hiding important information. #' @export diff --git a/R/zzz.R b/R/zzz.R index e8ee684..9b449f1 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -12,11 +12,11 @@ setLoadActions(function(ns) { exact_mass_balance = FALSE ) -# suppressWarnings({ -# register_standard(ratio(`2H` = to_ratio(abundance(0.00015574)), major = "1H", compound = "VSMOW")) # from IUPAC report -# register_standard(ratio(`13C` = 0.011237, major = "12C", compound = "VPDB")) -# register_standard(ratio(`15N` = 0.003677, major = "14N", compound = "Air")) -# register_standard(ratio(`18O` = 0.0020052, major = "16O", compound = "VSMOW")) -# register_standard(ratio(`34S` = 0.0045005, major = "32S", compound = "CDT")) -# }) + suppressWarnings({ + register_standard(ratio(`2H` = to_ratio(abundance(0.00015574)), major = "1H", compound = "VSMOW")) # from IUPAC report + register_standard(ratio(`13C` = 0.011237, major = "12C", compound = "VPDB")) + register_standard(ratio(`15N` = 0.003677, major = "14N", compound = "Air")) + register_standard(ratio(`18O` = 0.0020052, major = "16O", compound = "VSMOW")) + register_standard(ratio(`34S` = 0.0045005, major = "32S", compound = "CDT")) + }) }) diff --git a/man/arithmetic.Rd b/man/arithmetic.Rd index 13ff22d..9f80e72 100644 --- a/man/arithmetic.Rd +++ b/man/arithmetic.Rd @@ -38,8 +38,7 @@ have matching attributes (isotope name, major isotope, etc.). two \code{\link{abundance}} objects, see \code{\link{mass_balance}} for details \code{delta+-delta} is a shorthand for calculating the isotopic mass balance of -two \code{\link{delta}} objects, see \code{\link{mass_balance}} for details, -will use the global \code{\link{exact_mass_balance}} setting for the calculation +two \code{\link{delta}} objects, see \code{\link{mass_balance}} for details \code{alpha - 1} is a shorthand for converting a fractionation factor from alpha to epsilon notation. The ff object has to be in alpha notation, @@ -69,8 +68,8 @@ This is a shorthand for the \link{to_ff} function. either the denominator names or numerator names of the two objects are identical (i.e. they "cancel"). This is a shorthand for the \link{to_ff} function. -\code{delta/delta} creates an \code{\link{alpha}} fractionation factor object that +\code{delta/delta} creates an \code{\link{fractionation_factor}} object that describes the fractionation factor between the two compounds, requires the reference -name of the two delta values to be identical. This is a shorthand for the \link{frac_factor} function. +name of the two delta values to be identical. This is a shorthand for the \link{to_ff} function. } diff --git a/man/delta.Rd b/man/delta.Rd index d2ebc27..acd7500 100644 --- a/man/delta.Rd +++ b/man/delta.Rd @@ -35,8 +35,7 @@ another notation by using \code{\link{switch_notation}}. } \details{ For mass balance calculations with delta values, simply add the appropriate weights (if different from -the default) and use \code{delta(...) + delta(...)}. Use \code{\link{exact_mass_balance}(TRUE/FALSE)} -to adjust how these are calculated. +the default) and use \code{delta(...) + delta(...)}. } \examples{ delta(50, notation = "permil") # enter as permil value diff --git a/man/fractionate.Rd b/man/fractionate.Rd index a003868..729331d 100644 --- a/man/fractionate.Rd +++ b/man/fractionate.Rd @@ -14,9 +14,9 @@ fractionate(frac, iso) an object of the same type as \code{iso} } \description{ -This function calculates the outcome of isotopic fractionation by a \code{\link{fractionation_fractor}} +This function calculates the outcome of isotopic fractionation by a \code{\link{fractionation_factor}} and can be applied to \code{\link{ratio}} data, \code{\link{delta}} values or other -\code{\link{fractionation_fractor}} objects. +\code{\link{fractionation_factor}} objects. } \note{ Several of these calculations are also diff --git a/man/fractionation_factor.Rd b/man/fractionation_factor.Rd index 4f1b51d..cf1db4b 100644 --- a/man/fractionation_factor.Rd +++ b/man/fractionation_factor.Rd @@ -26,13 +26,13 @@ See \code{\link{switch_notation}} on details how to convert between notations.} \item{cbot}{- name of the compound representing the bottom isotope ratio [optional]} } \description{ -FIXME, change description -Generate a fractionation factor (alpha value = ratio of two isotope ratios) object. See \link{isotopia} for general information on initializing -and converting isotope data objects. -Fractionation factors can be easily converted from values in one notation to values in +Generate a fractionation factor object. Can be initialized in \code{alpha} and +\code{epsilon} notation. Fractionation factors can be easily converted from values in one notation to values in another notation by using \code{\link{switch_notation}}. } \details{ +See \link{isotopia} for general information on initializing +and converting to other isotope data objects. The \code{ff} function is a shorthand for \code{fractionation_factor} but otherwise identical. } \seealso{ diff --git a/man/get_value.Rd b/man/get_value.Rd index 8a58288..e208674 100644 --- a/man/get_value.Rd +++ b/man/get_value.Rd @@ -3,15 +3,15 @@ \alias{get_value} \title{Retrieve isotope object's primitive values} \usage{ -get_value(iso, notation = "raw") +get_value(iso, notation = iso@notation) } \arguments{ \item{notation}{specifiy which notation to return the value in (default is the notation -that hte object is in)} +that the object is in)} } \value{ In the case of a single isotope object (Isoval), returns the numeric -vector of raw values stored in the object (same as \code{\link{as.numeric}}). +vector of raw values stored in the object (same as \code{\link[base]{as.numeric}}). In the case of an isotope system (Isosys), returns the data frame underlying the object with all its isotope value objects also replaced with their numeric raw values. To just get the data @@ -22,7 +22,7 @@ This function returns an isotope object's (single value or isotope system) primitive data value(s). } \seealso{ -\code{\link{as.numeric}}, \code{\link{as.data.frame}}, \code{\link[base]{as.data.frame}} (base method) +\code{\link[base]{as.numeric}}, \code{\link{as.data.frame}}, \code{\link[base]{as.data.frame}} (base method) Other data type attributes: \code{\link{get_label}}, \code{\link{get_name}}, \code{\link{get_units}}; diff --git a/man/mass_balance.Rd b/man/mass_balance.Rd index 0241ad6..86605f1 100644 --- a/man/mass_balance.Rd +++ b/man/mass_balance.Rd @@ -3,13 +3,13 @@ \alias{mass_balance} \title{Calculate isotope mass balance} \usage{ -mass_balance(iso, iso2, ..., exact = exact_mass_balance()) +mass_balance(iso, iso2, ..., exact = get_iso_opts("exact_mass_balance")) } \arguments{ \item{...}{- any number of weighted isotope value objects (have to be all either abundance or delta)} -\item{exact}{- whether to calculate mass balance of delta values exactly (default FALSE), -use exact_mass_balance to set this paramter globally} +\item{exact}{- whether to calculate mass balance of delta values exactly (default FALSE), not +fully implemented yet} } \value{ weighted abundance or delta value object that represents the combination of the parameters diff --git a/man/quietly.Rd b/man/quietly.Rd index ad4fee0..8c52d5c 100644 --- a/man/quietly.Rd +++ b/man/quietly.Rd @@ -8,7 +8,7 @@ quietly(expr) \description{ This small utility function is just a convenient wrapper for running isotope calculations silently without outputting any of the warnings or -messages (it uses \link{suppressMessages} and \link{suppressWarnings} +messages (it uses \link[base]{suppressMessages} and \link[base]{suppressWarnings} internally) that might occur. Use with care to suppress warnings, you might end up hiding important information. } diff --git a/man/to_ff.Rd b/man/to_ff.Rd index e80b1fe..9b56f24 100644 --- a/man/to_ff.Rd +++ b/man/to_ff.Rd @@ -17,7 +17,7 @@ isotope \code{\link{fraction_factor}} object if parameters can be converted, an Calculate/convert to an isotope \code{\link{fractionation_factor}} } \details{ -The \code{frac_factor(...)} function calculates the fractionation factor between two isotope data objects +The \code{to_ff(...)} function calculates the fractionation factor between two isotope data objects (for example two \code{\link{delta}} values, two \code{\link{ratio}}, or two \code{\link{ff}}). All calculatinos are only permissible if the isotope values have matching attributes and fractionation factors will be returend in the default notation diff --git a/tests/testthat/test-05-data.R b/tests/testthat/test-05-data.R index e4ae225..259dea2 100644 --- a/tests/testthat/test-05-data.R +++ b/tests/testthat/test-05-data.R @@ -14,7 +14,7 @@ test_that("Testing that reference standards can be properly registered and retri expect_error(get_standard(name = "VSMOW"), "More than one") expect_error(get_standard(minor = "3H"), "No reference ratio registered") expect_equal(get_standard(minor = "2H", major = "1H", name = "VSMOW"), ratio(`2H` = 0.00015575, major = "1H", compound = "VSMOW")) - expect_message(to_ratio(delta(`2H` = -100, major = "1H", ref = "VSMOW")), "Successfully found a matching standard") + expect_message(to_ratio(delta(`2H` = -100, major = "1H", ref = "VSMOW")), "Successfully found a registered standard") expect_equal(to_ratio(delta(`2H` = 100, major = "1H", ref = "VSMOW")), ratio(`2H` = 1.1 * 0.00015575, major = "1H")) expect_is(get_iso_opts("standards"), "data.frame") })