#' @title Calculates the first dissociation constant of carbonic acid (mol/kg)
#' @description Calculates the first dissociation constant of carbonic acid for a
#' given temperature, salinity and pressure. Calls the K1() function in the seacarb
#' package, which returns units of mol/kg. Units are converted from kg to volume (L)
#' using water density given by the rho() function in seacarb.
#' @importFrom seacarb K1
#' @importFrom seacarb rho
#' @usage get.K1(temperature)
#' @param temperature Water temperature in degrees Celsius.
#' @param salinity Salinity in practical salinity units (PSU). Defaults to 0.
#' @param pressure Surface pressure in atmospheres. Defaults to 1.
#' @return Numeric vector of K1 in units of mol/L.
#' @author Gordon W. Holtgrieve (gholt@uw.edu)
#' @export
get.K1 <- function(temperature, salinity=0){
# Error handling
if(is.null(temperature)) stop("'temperature' missing with no defualt.")
oldw <- getOption("warn") # Keeps seacarb from getting grumpy.
options(warn = -1)
K1_kg <- seacarb::K1(S=salinity, T=temperature, P=0, k1k2="m06", warn="n") # Units mol/kg
rho <- seacarb::rho(S = salinity, T = temperature, P = 0) # Density in kg/m3
K1_ <- K1_kg * rho / 1000 # Convert from kg water to L
attributes(K1_) <- NULL # Strip attributes
options(warn = oldw) # Returns to original settings
return(K1_)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.