Skip to content

Commit

Permalink
version 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bappa10085 authored and cran-robot committed Feb 21, 2023
0 parents commit 077e545
Show file tree
Hide file tree
Showing 9 changed files with 455 additions and 0 deletions.
29 changes: 29 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Package: soilchemistry
Title: Computation of Properties Related to Soil Chemical Environment
and Nutrient Availability
Version: 0.1.0
Authors@R:
c(person(given = "Bappa",
family = "Das",
role = c("aut", "cre"),
email = "bappa.iari.1989@gmail.com",
comment = c(ORCID = "0000-0003-1286-1492")),
person("Debarup", "Das", email = "debarupds@gmail.com", role = c("aut", "ctb"),
comment = c(ORCID = "0000-0002-0706-3392")),
person("Mandira", "Barman", role = c("aut", "ctb"),
comment = c(ORCID = "0000-0001-7074-2286")),
person("Debrup", "Ghosh", role = c("aut", "ctb"),
comment = c(ORCID = "0000-0002-4060-6336")))
Description: Facilitates basic and equation-based analyses of some important soil properties related to soil chemical environment and nutrient availability to plants. Freundlich H (1907). <doi:10.1515/zpch-1907-5723>. Datta SP, Bhadoria PBS (1999). <doi:10.1002%2F%28SICI%291522-2624%28199903%29162%3A2%3C183%3A%3AAID-JPLN183%3E3.0.CO%3B2-A>."Boron adsorption and desorption in some acid soils of West Bengal, India". Langmuir I (1918). <doi:10.1021/ja02242a004> "The adsorption of gases on plane surfaces of glass, mica, and platinum". Khasawneh FE (1971). <doi:10.2136/sssaj1971.03615995003500030029x> "Solution ion activity and plant growth".
License: GPL (>= 3)
Maintainer: Bappa Das <bappa.iari.1989@gmail.com>
Encoding: UTF-8
RoxygenNote: 7.2.3
NeedsCompilation: no
Packaged: 2023-02-20 04:10:45 UTC; Bappa
Author: Bappa Das [aut, cre] (<https://orcid.org/0000-0003-1286-1492>),
Debarup Das [aut, ctb] (<https://orcid.org/0000-0002-0706-3392>),
Mandira Barman [aut, ctb] (<https://orcid.org/0000-0001-7074-2286>),
Debrup Ghosh [aut, ctb] (<https://orcid.org/0000-0002-4060-6336>)
Repository: CRAN
Date/Publication: 2023-02-21 11:10:02 UTC
8 changes: 8 additions & 0 deletions MD5
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
6d5c6dd81d559a76abc051bab9bd574e *DESCRIPTION
186d1d742e02c02d41aecbbd15a57959 *NAMESPACE
5dc3e00334ee61199eefcbeb0c7a5af6 *R/soilchemistry.R
8a985229a14bbe397450ec807a4869b6 *man/Freundlich_A.Rd
968d58a39a11f22f5bb76411cd693b29 *man/Freundlich_D.Rd
d6722c057757095997bf179ebf6a46cb *man/Langmuir.Rd
c56fd4d52b39ab4efc178b78597dba3e *man/SP.Rd
9540ddcec38b402f0a84ddcfdfe318b8 *man/df_sordes.Rd
11 changes: 11 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Generated by roxygen2: do not edit by hand

export(Freundlich_A)
export(Freundlich_D)
export(Langmuir)
export(SP)
export(df_sordes)
importFrom(graphics,abline)
importFrom(graphics,legend)
importFrom(stats,coef)
importFrom(stats,lm)
240 changes: 240 additions & 0 deletions R/soilchemistry.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
#' @title Example Data Frame for adsorption, desorption, and supply parameter
#' @description User is advised to prepare the data as suggested in the example to fit adsorption or desorption data pertaining to a particular nutrient, e.g., phosphorus (as phosphate), sulphur (as sulphate), micronutrient cations or anions, silicon (as silicate), etc. in soil to the functions namely, Freundlich_A, Freundlich_D, Langmuir, and SP. However, to use these functions, researchers should carry out the adsorption-desorption study in the method described as follows: W g (e.g., 2 g) of processed soil samples are taken in a series of 50 mL centrifuge tubes (polypropylene) each containing V mL (e.g., 20 mL) 0.1 M sodium chloride solution with different levels (e.g., 10, 20, 40, 60, … mg/L) of the nutrient under consideration (e.g., P). The tubes are shaken continuously for a defined period (e.g., 24 h) using a mechanical shaker. Immediately after that, each of them is centrifuged (e.g., at 10000 rpm) for sufficient time (e.g., 10-12 min), and a certain volume (e.g., 15 mL) of clear aliquot is pipetted out and filtered through a Whatman No. 42 filter paper. Then the nutrient content (e.g., P) in the filtrate is estimated by standard procedures. The difference between the quantities of the nutrient in the bathing solution before (initial concentration) and after equilibration (equilibrium or final concentration) is taken as the amount of the nutrient adsorbed by the soil from bathing solution. For desorption study, once supernatant is removed after completion of the adsorption step, a certain volume (e.g., 15 mL) of 0.1 M sodium chloride solution is added in the same sample to reach a final volume (Vfinal). For convenience in calculation, Vfinal should be equal to V (as taken initially). Generally, soil sample with the highest level of added nutrient from the adsorption study is used in desorption experiment. With the help of mechanical shaker, the soil is re-suspended and equilibrated for 12 h. After shaking, the tubes are centrifuged (e.g., at 10000 rpm) for sufficient time (e.g., 10–12 min), and the same volume (as in the previous step, e.g., 15 mL) of clear supernatant solution is pipetted out for determination of the concentration of the nutrient. This process can be repeated multiple times depending on the objective and convenience of the researcher. The difference between equilibrium concentration at a particular desorption step and equilibrium concentration previous to that desorption step, multiplied by solution:soil ratio (e.g., 20:2) is considered as desorbed amount of the nutrient. The adsorbed amount remaining after each desorption step can be computed by subtracting the desorbed amount at a particular step from the amount of adsorbed nutrient present before that desorption step.
#' @usage df_sordes
#' @format Write the following notations on the spreadsheet:
#' Initial_conc for Initial concentration (mg/L) of the added element, e.g., phosphorus
#' Equilibrium_conc for Final or equilibrium concentration (mg/L) after adsorption of the same element
#' Cf_Des for Final or equilibrium concentration (mg/L) after desorption of the same element

#' @export
df_sordes = read.table(text = "Initial_conc Equilibrium_conc Cf_Des
10 0.619589386 13.62847222
20 1.633333333 7.477678571
40 17.2781449 6.051587302
60 35.18963333 4.836309524", header = TRUE)

#' @title Freundlich isotherm fitted to adsorption data
#'
#' @description The linear form of Freundlich adsorption isotherm can be fitted to adsorption data to find out the empirical constants of Freundlich equation (Freundlich, 1926).
#' @importFrom graphics abline legend
#' @importFrom stats coef lm
#'
#' @usage Freundlich_A(W = W, V = V, Ci = Ci, Cf = Cf,...)
#'
#' @param W Mass of soil sample (g)
#' @param V Volume of extractant solution (mL)
#' @param Ci Initial concentration (mg/L) of the added element, e.g., phosphorus
#' @param Cf Final or equilibrium concentration (mg/L) after adsorption of the same element
#' @param ... Any other argument that can be passed to base plot
#' @return a - empirical constant (unitless)
#' 1/n - empirical constant (unitless)
#'
#' @references Freundlich, H., 1926. Colloid and Capillary Chemistry. London: Methuen.
#' @details Freundlich equation/isotherm is used to study the adsorption behavior of any element in soils (Freundlich, 1926). It is of the general form: x/m= ac^(1/n), where ‘x’ is the amount of the adsorbate (e.g., P, Ni, etc.) adsorbed on ‘m’ amount of the adsorbent (e.g., soil), and ‘c’ is the equilibrium concentration of the adsorbate. This adsorption model helps to understand the relationship between quantity of any element adsorbed per unit soil weight and their concentration in soil solution. Freundlich equation does not predict or include maximum adsorption capacity of soil, so better suited to dilute solutions (of the element under consideration) in contact with the adsorbent. The ‘a’ and ‘1/n’ are two empirical-constants, sensitive to the given adsorbent-adsorbate system and temperature. Freundlich ‘a’ indicates the binding affinity of any element in soil. The ‘1/n’ is the exponent of the equilibrium concentration term in the Freundlich equation, and is always < 1 indicating that the energy of adsorption decreases logarithmically as the fraction of adsorbent-surface covered by the adsorbate increases with increasing equilibrium concentration.
#' @export
#' @examples
#' with(data = df_sordes, Freundlich_A(W = 2, V = 20, Ci = Initial_conc,
#' Cf = Equilibrium_conc))

Freundlich_A <- function(W = W, V = V, Ci = Ci, Cf = Cf,...){

p_adsorbed <- (Ci - Cf )*(V/W)
logC <- log10(Cf)
logX <- log10(p_adsorbed)

myplot <- function(x, y, xlab=deparse(substitute(x)), ylab=deparse(substitute(y)),...){
plot(x, y, xlab=xlab, ylab=ylab, ...)
}
myplot(x = logC, y = logX, ...)
abline(lm(logX ~ logC), col = "blue")
fit.slr <- lm(logX ~ logC)

##Round the coefficients for better output
cf <- round(coef(fit.slr), 3)

##Make the regression equation
eq <- paste0("y = ", cf[1],
ifelse(sign(cf[2])==1, " + ", " - "), abs(cf[2]), " x ")

#Get the R2 value
Rsq = format(summary(fit.slr)$r.squared,digits=3)

##Printing of the equation and R2 on the plot
legend("topleft", legend = c(eq, as.expression(bquote(R^2 == .(Rsq)))), bty = "n")
a <- 10^coef(fit.slr)[[1]]
onebyn <- coef(fit.slr)[[2]]
return(list(a = a, onebyn = onebyn))
}

#' @title Freundlich isotherm for desorption data in soil
#'
#' @description This function fits Freundlich adsorption isotherm to data pertaining to desorption of an adsorbed nutrient, e.g., phosphorus (as phosphate), sulphur (as sulphate), micronutrient cations or anions, silicon (as silicate), etc. in soil.
#' @importFrom graphics abline legend
#' @importFrom stats coef lm
#' @usage Freundlich_D(W = W, V = V, Ci = Ci, Cf = Cf, Cf_Des = Cf_Des, Vres= Vres,
#' Vfinal = Vfinal, onebyn_ads = onebyn_ads, ...)
#'
#' @param W Mass of soil sample (g)
#' @param V Volume of extractant solution (mL)
#' @param Ci Initial concentration (mg/L) of the added element, e.g., phosphorus
#' @param Cf Final or equilibrium concentration (mg/L) after adsorption of the same element
#' @param Cf_Des Final or equilibrium concentration (mg/L) after each desorption step of the same element
#' @param Vres Volume of carried over solution from previous adsorption or desorption step (mL)
#' @param Vfinal Final volume of the solution for each desorption step (mL)
#' @param onebyn_ads Values of ‘1/n’ obtained from Freundlich_A
#' @param ... Any other argument that can be passed to base plot
#'
#' @return a - empirical constant (unitless)
#' 1/n - empirical constant (unitless)
#'
#' @references Barman, M., Datta, S.P., Rattan, R.K., Meena, M.C., 2013. Sorption and desorption of nickel in soils in relation to its availability to plants. Agrochimica LVII (3), 235–249.
#'
#' @export
#' @examples
#' with(data = df_sordes, Freundlich_D(W = 2, V = 20, Ci = Initial_conc, Cf = Equilibrium_conc,
#' Cf_Des = Cf_Des, Vres= 5, Vfinal = 20, onebyn_ads = 0.2056263))
#'
Freundlich_D <- function(W = W, V = V, Ci = Ci, Cf = Cf, Cf_Des = Cf_Des, Vres= Vres,
Vfinal = Vfinal, onebyn_ads = onebyn_ads, ...){
##Initialize the calculation
Ads <- (Ci - Cf)*(V/W)
Ads_Des <- numeric(length(Cf_Des))
Ci_x <- max(Cf, na.rm=T)/(Vfinal/Vres)
Ads_Des[[1]] <- Ads_x <- max(Ads, na.rm=T) - (Cf_Des[[1]] - Ci_x)*(Vfinal/W)
##For loop
for (i in seq_along(Cf_Des)[-1]) {
Des_x <- (Cf_Des[[i]] - Cf_Des[[i - 1]]/(Vfinal/Vres))*(Vfinal/W)
Ads_Des[[i]] <- Ads_x <- Ads_x - Des_x
}
## processing
log_Cf_Des <- log10(Cf_Des)
log_Ads_Des <- log10(Ads_Des)

myplot <- function(x, y, xlab=deparse(substitute(x)), ylab=deparse(substitute(y)),...){
plot(x, y, xlab=xlab, ylab=ylab, ...)
}
myplot(x = log_Cf_Des, y = log_Ads_Des, ...)
abline(lm(log_Ads_Des ~ log_Cf_Des), col = "blue")
fit.slr <- lm(log_Ads_Des ~ log_Cf_Des)

##Round the coefficients for better output
cf <- round(coef(fit.slr), 4)

##Make the regression equation
eq <- paste0("y = ", cf[1],
ifelse(sign(cf[2])==1, " + ", " - "), abs(cf[2]), " x ")

#Get the R2 value
Rsq = format(summary(fit.slr)$r.squared, digits=3)

##Printing of the equation and R2 on the plot
legend("topleft", legend = c(eq, as.expression(bquote(R^2 == .(Rsq)))), bty = "n")
a <- 10^coef(fit.slr)[[1]]
onebyn <- coef(fit.slr)[[2]]
DI <- onebyn_ads/onebyn
return(list(a = a, onebyn = onebyn, DI = DI))
}

#' @title Langmuir isotherm fitted to adsorption data
#' @description The linear form of Langmuir adsorption isotherm can be fitted to adsorption data to find out adsorption maxima, affinity coefficient, and maximum buffering capacity (Langmuir, 1918).
#' @importFrom graphics abline legend
#' @importFrom stats coef lm
#' @usage Langmuir(W = W, V = V, Ci = Ci, Cf = Cf,...)
#' @param W Mass of soil sample (g)
#' @param V Volume of extractant solution (mL)
#' @param Ci Initial concentration (mg/L) of the added element, e.g., phosphorus
#' @param Cf Final or equilibrium concentration (mg/L) after adsorption of the same element
#' @param ... Any other argument that can be passed to base plot
#' @return b - Maximum monolayer adsorption or adsorption maxima (mg/kg)
#' k - Constant related to binding energy or the affinity coefficient for the nutrient, e.g., P (L/mg)
#' MBC - Maximum buffering capacity of soil for the nutrient under consideration (L/kg)
#'
#' @references Havlin, J.L., Tisdale, S.L., Nelson, W.L., Beaton, J.D., 2016. Phosphorus. In: Soil fertility and fertilizers. Pearson Education India, pp.160–198.
#' Holford, I.C.R., Mattingly, G.E.G., 1976. Phosphate adsorption and plant availability of phosphate. Plant and Soil 44, 377–389. https://doi.org/10.1007/BF00015889
#' Langmuir, I., 1918. The adsorption of gases on plane surfaces of glass, mica, and platinum. Journal of American Chemical Society 40, 1361–1403. https://doi.org/10.1021/ja02242a004
#' Shirvani, M., Shariatmadari, H., Kalbasi, M., 2005. Phosphorus buffering capacity indices as related to soil properties and plant uptake. Journal of Plant Nutrition, 28, 537–550. https://doi.org/10.1081/PLN-200049235
#' @export
#' @examples
#' with(data = df_sordes, Langmuir(W = 2, V = 20, Ci = Initial_conc, Cf = Equilibrium_conc))

Langmuir <- function(W = W, V = V, Ci = Ci, Cf = Cf,...){

p_adsorbed <- (Ci - Cf)*(V/W)
CbyX <- Cf/p_adsorbed

myplot <- function(x, y, xlab=deparse(substitute(x)), ylab=deparse(substitute(y)),...){
plot(x, y, xlab=xlab, ylab=ylab, ...)
}
myplot(x = Cf, y = CbyX, ...)
abline(lm(CbyX ~ Cf), col = "blue")
fit.slr <- lm(CbyX ~ Cf)

##Round the coefficients for better output
cf <- round(coef(fit.slr), 4)

##Make the regression equation
eq <- paste0("y = ", cf[1],
ifelse(sign(cf[2])==1, " + ", " - "), abs(cf[2]), " x ")

#Get the R2 value
Rsq = format(summary(fit.slr)$r.squared, digits=3)

##Printing of the equation and R2 on the plot
legend("topleft", legend = c(eq, as.expression(bquote(R^2 == .(Rsq)))), bty = "n")
b <- 1/coef(fit.slr)[[2]]
k <- coef(fit.slr)[[2]]/coef(fit.slr)[[1]]
MBC <- b*k
return(list(b = b, k = k, MBC = MBC))
}

#' @title Supply parameter of phosphorus in soil
#' @description This function generates the supply parameter (SP) of phosphorus in soil as described by Khasawneh and Copeland (1973).
#' @importFrom graphics abline legend
#' @importFrom stats coef lm
#' @usage SP(W = W, V = V, Ci = Ci, Cf = Cf,...)
#' @param W Mass of soil sample (g)
#' @param V Volume of extractant solution (mL)
#' @param Ci Initial concentration (mg/L) of the added element, e.g., phosphorus
#' @param Cf Final or equilibrium concentration (mg/L) after adsorption of the same element
#' @param ... Any other argument that can be passed to base plot
#'
#' @return SP - Supply parameter (mg^0.5)/(kg L)^0.25
#'
#' @references Khasawneh, F.E., 1971. Solution ion activity and plant growth. Soil Science Society of America Proceedings 35, 426–436.
#' Khasawneh, F.E., Copeland, J.P., 1973. Cotton root growth and uptake of nutrients: relation of phosphorus uptake to quantity, intensity, and buffering capacity. Soil Science Society of America Proceedings 37, 250–254.
#' @export
#' @examples
#' with(data = df_sordes, SP(W = 2, V = 20, Ci = Initial_conc, Cf = Equilibrium_conc,
#' col = rgb(red = 1, green = 0, blue = 0, alpha = 0.5), pch = 16, cex = 1))

SP <- function(W = W, V = V, Ci = Ci, Cf = Cf,...){

p_adsorbed <- (Ci - Cf)*(V/W)
onebyC <- 1/Cf
onebyX <- 1/p_adsorbed

myplot <- function(x, y, xlab=deparse(substitute(x)), ylab=deparse(substitute(y)),...){
plot(x, y, xlab=xlab, ylab=ylab, ...)
}
myplot(x = onebyC, y = onebyX, ...)
abline(lm(onebyX ~ onebyC), col = "blue")
fit.slr <- lm(onebyX ~ onebyC)

##Round the coefficients for better output
cf <- round(coef(fit.slr), 4)

##Make the regression equation
eq <- paste0("y = ", cf[1],
ifelse(sign(cf[2])==1, " + ", " - "), abs(cf[2]), " x ")

#Get the R2 value
Rsq = format(summary(fit.slr)$r.squared, digits=3)

##Printing of the equation and R2 on the plot
legend("topleft", legend = c(eq, as.expression(bquote(R^2 == .(Rsq)))), bty = "n")

k1 <- 1/coef(fit.slr)[[1]]
k2 <- k1*coef(fit.slr)[[2]]
SP <- (k1*k2)^(1/4)*sqrt(Cf*p_adsorbed/(k1*k2))
return(list(SP = SP))
}
36 changes: 36 additions & 0 deletions man/Freundlich_A.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 077e545

Please sign in to comment.