I have several large .R files. I want to merge them into a single .R file. Here are two example .R files
MN.R
#' @title Mineral N i.e., summation of ammonium-N and nitrate-N in soil
#'
#' @description This function determines the amount of mineral N (ammonium-N + nitrate-N) in soil as extracted by 2 M KCl, expressed in terms of oven-dried soil mass (Rowell, 1994).
#'
#' @usage Mineral_N(W = W, m = m, VA = VA, VE = VE, VS = VS, VB = VB, X = X)
#'
#' @param W Mass of moist soil sample (g)
#' @param m Moisture content of the field-moist soil sample (% w/w)
#' @param VA Volume of aliquot of the extract (mL) taken for distillation
#' @param VE Volume of 2 M KCl (mL) added as extractant
#' @param VS Volume of standard sulphuric acid solution (mL) consumed in titration with soil
#' @param VB Volume of standard sulphuric acid solution (mL) consumed in titration without soil (i.e., blank titration)
#' @param X Normality of standard sulphuric acid solution
#' @return N_mgkg - Mineral N in soil (mg/kg) (expressed in terms of oven-dried soil mass)
#'
#'
#' @references Biswas, D.R. (2018) Determination of different forms of nitrogen in soil and total N in plant. In Manual on Advanced Techniques for Analysis of Nutrients and Pollutant Elements in Soil, Plant and Human (S.P. Datta, M.C. Meena, B.S. Dwivedi, A.K. Shukla (Eds.)), Westville Publishing House, New Delhi, pp. 57-68.
#'
#' Rowell, D.L. (1994) Soil Science Methods and Application, Pearson Education Ltd., Essex, England.
#'
#' @details Mineral N in soil consists of ammonium and nitrate ions present on soil exchange sites or solution or both. It can be extracted by 2 M KCl. The extract is steam-distilled in the presence of magnesium oxide and Devarda’s alloy (Cu: Al: Zn :: 50: 45: 5) to liberate ammonia. The evolved ammonia is absorbed in 2% boric acid solution containing mixed indicator, pH 4.5, and titrated against standard sulphuric acid solution to know the volume of the boric acid consumed during ammonia absorption (Rowell, 1994; Biswas, 2018).
#'
#' @export
#' @examples
#' with(data = df_Minearl_N, Mineral_N(W = Mass_Moistsoil, m = Moisture_Percent,
#' VA = Vol_Aliquot, VE = Vol_Extractant, VS = Vol_Sulphuric_Soil,
#' VB = Vol_Sulphuric_Blank, X = Normality_Sulphuric))
#'
Mineral_N <- function(W = W, m = m, VA = VA, VE = VE, VS = VS, VB = VB, X = X){
N_mgkg = (VS-VB)*14*X*(VE+(W*m)/(100+m))*(100+m)*10/(VA*W)
return(N_mgkg)
}
WBC.R
#' @title Oxidizable organic carbon (C) or Walkley-Black C in soil
#'
#' @description The oxidizable organic C or Walkley-Black C (WBC) in soil is obtained by this function based on the method described by Walkley and Black (1934).
#'
#' @usage WBC(W = W, Vk = Vk, Vb = Vb, Vs = Vs, Nk = Nk)
#'
#' @param W Mass of soil sample (g)
#' @param Vk Volume of potassium dichromate solution (mL)
#' @param Vb Volume of ferrous ammonium sulphate solution (mL) consumed in titration without soil (i.e., blank titration)
#' @param Vs Volume of ferrous ammonium sulphate solution (mL) consumed in titration with soil
#' @param Nk Normality of potassium dichromate solution
#' @return WBC_pc - Oxidizable organic C or Walkley-Black C in soil (%)
#' WBC_gkg - Oxidizable organic C or Walkley-Black C in soil (g/kg)
#'
#'
#' @references Basak RK (2000) Soil Testing and Recommendation: A Text Book. Kalyani Publishers, New Delhi, India.
#'
#' Walkley AJ, Black CA (1934) An estimation of the Degtjareff method for determining soil organic matter and a proposed modification of the chromic acid titration method. Soil Science 37, 29–38. doi:10.1097/00010694-193401000-00003
#'
#' @details Soil organic C is very important to soil fertility, nutrient cycling and C sequestration. Routine soil testing includes determination of oxidizable organic C as per the method described by Walkley and Black (1934). The oxidizable organic C mostly encompasses C present in partly decomposed organic matter and slightly the well decomposed organic matter in soil (Basak, 2000). The method suggested by Walkley and Black (1934) involves oxidation of soil organic C with an excess of standard (usually 1 N) potassium dichromate solution (usually, 10 mL for 1 g soil) in presence of concentrated sulphuric acid (20 mL). The unreacted potassium dichromate solution is titrated against freshly prepared ferrous ammonium sulphate solution to get the volume of potassium dichromate solution consumed in oxidizing soil organic C, from which the content of oxidizable organic C is calculated.
#' @export
#' @examples
#' with(data = df_WBC, WBC(W = Mass_Soil, Vk = Vol_Potassium_dichromate,
#' Vb = Vol_FAS_Blank, Vs = Vol_FAS_Soil, Nk = Normality_Potassium_dichromate))
#'
WBC <- function(W = W, Vk = Vk, Vb = Vb, Vs = Vs, Nk = Nk){
WBC_pc = Vk*(1-(Vs/Vb))*Nk*0.3/W
WBC_gkg = WBC_pc*10
return(list(WBC_pc = WBC_pc, WBC_gkg = WBC_gkg))
}
I want to merge them into single .R file like
Merged.R
#' @title Mineral N i.e., summation of ammonium-N and nitrate-N in soil
#'
#' @description This function determines the amount of mineral N (ammonium-N + nitrate-N) in soil as extracted by 2 M KCl, expressed in terms of oven-dried soil mass (Rowell, 1994).
#'
#' @usage Mineral_N(W = W, m = m, VA = VA, VE = VE, VS = VS, VB = VB, X = X)
#'
#' @param W Mass of moist soil sample (g)
#' @param m Moisture content of the field-moist soil sample (% w/w)
#' @param VA Volume of aliquot of the extract (mL) taken for distillation
#' @param VE Volume of 2 M KCl (mL) added as extractant
#' @param VS Volume of standard sulphuric acid solution (mL) consumed in titration with soil
#' @param VB Volume of standard sulphuric acid solution (mL) consumed in titration without soil (i.e., blank titration)
#' @param X Normality of standard sulphuric acid solution
#' @return N_mgkg - Mineral N in soil (mg/kg) (expressed in terms of oven-dried soil mass)
#'
#'
#' @references Biswas, D.R. (2018) Determination of different forms of nitrogen in soil and total N in plant. In Manual on Advanced Techniques for Analysis of Nutrients and Pollutant Elements in Soil, Plant and Human (S.P. Datta, M.C. Meena, B.S. Dwivedi, A.K. Shukla (Eds.)), Westville Publishing House, New Delhi, pp. 57-68.
#'
#' Rowell, D.L. (1994) Soil Science Methods and Application, Pearson Education Ltd., Essex, England.
#'
#' @details Mineral N in soil consists of ammonium and nitrate ions present on soil exchange sites or solution or both. It can be extracted by 2 M KCl. The extract is steam-distilled in the presence of magnesium oxide and Devarda’s alloy (Cu: Al: Zn :: 50: 45: 5) to liberate ammonia. The evolved ammonia is absorbed in 2% boric acid solution containing mixed indicator, pH 4.5, and titrated against standard sulphuric acid solution to know the volume of the boric acid consumed during ammonia absorption (Rowell, 1994; Biswas, 2018).
#'
#' @export
#' @examples
#' with(data = df_Minearl_N, Mineral_N(W = Mass_Moistsoil, m = Moisture_Percent,
#' VA = Vol_Aliquot, VE = Vol_Extractant, VS = Vol_Sulphuric_Soil,
#' VB = Vol_Sulphuric_Blank, X = Normality_Sulphuric))
#'
Mineral_N <- function(W = W, m = m, VA = VA, VE = VE, VS = VS, VB = VB, X = X){
N_mgkg = (VS-VB)*14*X*(VE+(W*m)/(100+m))*(100+m)*10/(VA*W)
return(N_mgkg)
}
#' @title Oxidizable organic carbon (C) or Walkley-Black C in soil
#'
#' @description The oxidizable organic C or Walkley-Black C (WBC) in soil is obtained by this function based on the method described by Walkley and Black (1934).
#'
#' @usage WBC(W = W, Vk = Vk, Vb = Vb, Vs = Vs, Nk = Nk)
#'
#' @param W Mass of soil sample (g)
#' @param Vk Volume of potassium dichromate solution (mL)
#' @param Vb Volume of ferrous ammonium sulphate solution (mL) consumed in titration without soil (i.e., blank titration)
#' @param Vs Volume of ferrous ammonium sulphate solution (mL) consumed in titration with soil
#' @param Nk Normality of potassium dichromate solution
#' @return WBC_pc - Oxidizable organic C or Walkley-Black C in soil (%)
#' WBC_gkg - Oxidizable organic C or Walkley-Black C in soil (g/kg)
#'
#'
#' @references Basak RK (2000) Soil Testing and Recommendation: A Text Book. Kalyani Publishers, New Delhi, India.
#'
#' Walkley AJ, Black CA (1934) An estimation of the Degtjareff method for determining soil organic matter and a proposed modification of the chromic acid titration method. Soil Science 37, 29–38. doi:10.1097/00010694-193401000-00003
#'
#' @details Soil organic C is very important to soil fertility, nutrient cycling and C sequestration. Routine soil testing includes determination of oxidizable organic C as per the method described by Walkley and Black (1934). The oxidizable organic C mostly encompasses C present in partly decomposed organic matter and slightly the well decomposed organic matter in soil (Basak, 2000). The method suggested by Walkley and Black (1934) involves oxidation of soil organic C with an excess of standard (usually 1 N) potassium dichromate solution (usually, 10 mL for 1 g soil) in presence of concentrated sulphuric acid (20 mL). The unreacted potassium dichromate solution is titrated against freshly prepared ferrous ammonium sulphate solution to get the volume of potassium dichromate solution consumed in oxidizing soil organic C, from which the content of oxidizable organic C is calculated.
#' @export
#' @examples
#' with(data = df_WBC, WBC(W = Mass_Soil, Vk = Vol_Potassium_dichromate,
#' Vb = Vol_FAS_Blank, Vs = Vol_FAS_Soil, Nk = Normality_Potassium_dichromate))
#'
WBC <- function(W = W, Vk = Vk, Vb = Vb, Vs = Vs, Nk = Nk){
WBC_pc = Vk*(1-(Vs/Vb))*Nk*0.3/W
WBC_gkg = WBC_pc*10
return(list(WBC_pc = WBC_pc, WBC_gkg = WBC_gkg))
}
I have seen some similar questions here and here and I have tried like:
# Load tidyverse
library(tidyverse)
# List files and source each
list.files("path_to_folder", full.names = TRUE) %>% map(source)
which runs without any error. Now how can I write it as one .R file?