knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
# Enable the KWB-R universe repository options(repos = c( kwbr = "https://kwb-r.r-universe.dev", CRAN = "https://cloud.r-project.org" )) # Install R package install.packages("geosalz.phreeqc")
library(geosalz.phreeqc) file_samples <- geosalz.phreeqc::package_file("phreeqc-input.csv") samples <- read.csv2(file_samples, check.names = FALSE) knitr::kable(samples) samples_tidy <- geosalz.phreeqc::tidy_samples(samples) %>% geosalz.phreeqc::convert_to_numeric_lab_values() samples_tidy
solutions_input <- geosalz.phreeqc::prepare_solutions_input( samples_tidy, title = "Test Dataset" )
Content of solutions_input
is shown below:
cat(solutions_input)
### Load PHREEQC database "phreeqc.dat" phreeqc::phrLoadDatabaseString(phreeqc::phreeqc.dat) ### Capture PHREEQC output normally sent to output file into a buffer phreeqc::phrSetOutputStringsOn(TRUE) ## Run PHREEQC with "solutions_input" phreeqc::phrRunString(input = solutions_input) ### Retrieves the phreeqc output as a character vector phreeqc_output <- phreeqc::phrGetOutputStrings() writeLines(phreeqc_output, "phreeqc_output.txt")
Here is the content of phreeqc_output
cat(paste0(phreeqc_output, collapse = "\n"))
sims <- geosalz.phreeqc::read_simulations(phreeqc_output) str(sims) sims_list <- geosalz.phreeqc::convert_simulations_to_list(sims) str(sims_list)
openxlsx::write.xlsx( x = sims_list, file = "phreeqc_output.xlsx", overwrite = TRUE )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.