├── .github ├── .gitignore ├── ISSUE_TEMPLATE │ ├── feature_request.md │ ├── documentation-improvement.md │ └── bug_report.md └── workflows │ ├── pkgdown.yaml │ └── R-CMD-check.yaml ├── vignettes ├── .gitignore ├── render-example.Rmd ├── examples.Rmd ├── render.Rmd ├── project.Rmd ├── customize.Rmd └── quarto.Rmd ├── LICENSE ├── figures ├── tn.png ├── soil.png ├── som.png ├── chemical.png ├── physical.png ├── ball-texture.png ├── biological.png ├── compaction.png ├── curve-less.png ├── curve-more.png ├── curve-table.png ├── som-spanish.png ├── tn-spanish.png ├── curve-optimal.png ├── sampling_scene.png ├── quality-results.png ├── aggregate-stability.png ├── compaction-spanish.png ├── curve-less-spanish.png ├── curve-more-spanish.png ├── curve-table-spanish.png ├── ball-texture-spanish.png ├── curve-optimal-spanish.png ├── quality-results-spanish.png └── aggregate-stability-spanish.png ├── data ├── washi_data.rda └── data_dictionary.rda ├── man ├── figures │ ├── logo.png │ ├── utf-8.png │ ├── render.png │ ├── create_soils.png │ ├── new_project.png │ ├── render-reports.png │ ├── project_wizard-1.png │ ├── project_wizard-2.png │ ├── parameterized-reports.png │ └── rendered_report_location.png ├── calculate_mode.Rd ├── summarize_by_project.Rd ├── get_table_headers.Rd ├── pull_unique.Rd ├── soils_example.Rd ├── get_n_texture_by_var.Rd ├── summarize_by_var.Rd ├── make_leaflet.Rd ├── prep_for_map.Rd ├── washi_data.Rd ├── create_soils.Rd ├── data_dictionary.Rd ├── style_ft.Rd ├── format_ft_colors.Rd ├── make_texture_triangle.Rd ├── make_ft.Rd ├── soils-package.Rd ├── unit_hline.Rd ├── convert_ggiraph.Rd ├── theme_facet_strip.Rd ├── set_scales.Rd ├── add_texture_points.Rd ├── add_legend.Rd └── make_strip_plot.Rd ├── inst ├── extdata │ ├── df_plot.RDS │ ├── headers.RDS │ └── tables.RDS ├── rstudio │ └── templates │ │ └── project │ │ ├── logo.png │ │ └── create_soils_project.dcf ├── templates │ ├── english │ │ ├── images │ │ │ ├── logo.png │ │ │ ├── biological.png │ │ │ ├── chemical.png │ │ │ └── physical.png │ │ ├── resources │ │ │ ├── word-template.docx │ │ │ └── styles.css │ │ ├── 08_looking-forward.qmd │ │ ├── 09_acknowledgement.qmd │ │ ├── data │ │ │ └── data-dictionary.csv │ │ ├── 02_section-template.qmd │ │ ├── 03_project-summary.qmd │ │ ├── R │ │ │ └── render-reports.R │ │ ├── 05_physical-measurements.qmd │ │ ├── 06_biological-measurements.qmd │ │ └── 07_chemical-measurements.qmd │ └── spanish │ │ ├── images │ │ ├── logo.png │ │ ├── biological.png │ │ ├── chemical.png │ │ └── physical.png │ │ ├── resources │ │ ├── word-template.docx │ │ └── styles.css │ │ ├── 09_acknowledgement.qmd │ │ ├── 08_looking-forward.qmd │ │ ├── data │ │ └── data-dictionary.csv │ │ ├── 03_project-summary.qmd │ │ ├── 02_section-template.qmd │ │ ├── R │ │ └── render-reports.R │ │ ├── 06_biological-measurements.qmd │ │ ├── 05_physical-measurements.qmd │ │ └── 07_chemical-measurements.qmd └── CITATION ├── pkgdown ├── favicon │ ├── favicon.ico │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ ├── apple-touch-icon.png │ ├── apple-touch-icon-120x120.png │ ├── apple-touch-icon-152x152.png │ ├── apple-touch-icon-180x180.png │ ├── apple-touch-icon-60x60.png │ └── apple-touch-icon-76x76.png ├── extra.css ├── _pkgdown.yml ├── index.Rmd └── index.md ├── tests ├── testthat │ ├── test-create-soils.R │ └── _snaps │ │ └── create-soils.md └── testthat.R ├── R ├── soils-package.R ├── globals.R ├── utils.R ├── data.R ├── create-soils.R ├── map.R ├── helpers.R └── tables.R ├── .gitignore ├── NEWS.md ├── .Rbuildignore ├── soils.Rproj ├── NAMESPACE ├── LICENSE.md ├── DESCRIPTION ├── data-raw └── example_data.R ├── README.Rmd └── README.md /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | *.R 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2022 2 | COPYRIGHT HOLDER: Washington State Department of Agriculture 3 | -------------------------------------------------------------------------------- /figures/tn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/figures/tn.png -------------------------------------------------------------------------------- /figures/soil.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/figures/soil.png -------------------------------------------------------------------------------- /figures/som.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/figures/som.png -------------------------------------------------------------------------------- /data/washi_data.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/data/washi_data.rda -------------------------------------------------------------------------------- /figures/chemical.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/figures/chemical.png -------------------------------------------------------------------------------- /figures/physical.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/figures/physical.png -------------------------------------------------------------------------------- /man/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/man/figures/logo.png -------------------------------------------------------------------------------- /man/figures/utf-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/man/figures/utf-8.png -------------------------------------------------------------------------------- /data/data_dictionary.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/data/data_dictionary.rda -------------------------------------------------------------------------------- /figures/ball-texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/figures/ball-texture.png -------------------------------------------------------------------------------- /figures/biological.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/figures/biological.png -------------------------------------------------------------------------------- /figures/compaction.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/figures/compaction.png -------------------------------------------------------------------------------- /figures/curve-less.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/figures/curve-less.png -------------------------------------------------------------------------------- /figures/curve-more.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/figures/curve-more.png -------------------------------------------------------------------------------- /figures/curve-table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/figures/curve-table.png -------------------------------------------------------------------------------- /figures/som-spanish.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/figures/som-spanish.png -------------------------------------------------------------------------------- /figures/tn-spanish.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/figures/tn-spanish.png -------------------------------------------------------------------------------- /inst/extdata/df_plot.RDS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/inst/extdata/df_plot.RDS -------------------------------------------------------------------------------- /inst/extdata/headers.RDS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/inst/extdata/headers.RDS -------------------------------------------------------------------------------- /inst/extdata/tables.RDS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/inst/extdata/tables.RDS -------------------------------------------------------------------------------- /man/figures/render.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/man/figures/render.png -------------------------------------------------------------------------------- /figures/curve-optimal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/figures/curve-optimal.png -------------------------------------------------------------------------------- /figures/sampling_scene.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/figures/sampling_scene.png -------------------------------------------------------------------------------- /figures/quality-results.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/figures/quality-results.png -------------------------------------------------------------------------------- /man/figures/create_soils.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/man/figures/create_soils.png -------------------------------------------------------------------------------- /man/figures/new_project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/man/figures/new_project.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/pkgdown/favicon/favicon.ico -------------------------------------------------------------------------------- /figures/aggregate-stability.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/figures/aggregate-stability.png -------------------------------------------------------------------------------- /figures/compaction-spanish.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/figures/compaction-spanish.png -------------------------------------------------------------------------------- /figures/curve-less-spanish.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/figures/curve-less-spanish.png -------------------------------------------------------------------------------- /figures/curve-more-spanish.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/figures/curve-more-spanish.png -------------------------------------------------------------------------------- /figures/curve-table-spanish.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/figures/curve-table-spanish.png -------------------------------------------------------------------------------- /man/figures/render-reports.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/man/figures/render-reports.png -------------------------------------------------------------------------------- /figures/ball-texture-spanish.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/figures/ball-texture-spanish.png -------------------------------------------------------------------------------- /figures/curve-optimal-spanish.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/figures/curve-optimal-spanish.png -------------------------------------------------------------------------------- /man/figures/project_wizard-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/man/figures/project_wizard-1.png -------------------------------------------------------------------------------- /man/figures/project_wizard-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/man/figures/project_wizard-2.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/pkgdown/favicon/favicon-16x16.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/pkgdown/favicon/favicon-32x32.png -------------------------------------------------------------------------------- /figures/quality-results-spanish.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/figures/quality-results-spanish.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/pkgdown/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /figures/aggregate-stability-spanish.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/figures/aggregate-stability-spanish.png -------------------------------------------------------------------------------- /inst/rstudio/templates/project/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/inst/rstudio/templates/project/logo.png -------------------------------------------------------------------------------- /inst/templates/english/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/inst/templates/english/images/logo.png -------------------------------------------------------------------------------- /inst/templates/spanish/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/inst/templates/spanish/images/logo.png -------------------------------------------------------------------------------- /man/figures/parameterized-reports.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/man/figures/parameterized-reports.png -------------------------------------------------------------------------------- /man/figures/rendered_report_location.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/man/figures/rendered_report_location.png -------------------------------------------------------------------------------- /inst/templates/english/images/biological.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/inst/templates/english/images/biological.png -------------------------------------------------------------------------------- /inst/templates/english/images/chemical.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/inst/templates/english/images/chemical.png -------------------------------------------------------------------------------- /inst/templates/english/images/physical.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/inst/templates/english/images/physical.png -------------------------------------------------------------------------------- /inst/templates/spanish/images/biological.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/inst/templates/spanish/images/biological.png -------------------------------------------------------------------------------- /inst/templates/spanish/images/chemical.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/inst/templates/spanish/images/chemical.png -------------------------------------------------------------------------------- /inst/templates/spanish/images/physical.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/inst/templates/spanish/images/physical.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/pkgdown/favicon/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/pkgdown/favicon/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/pkgdown/favicon/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/pkgdown/favicon/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/pkgdown/favicon/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /tests/testthat/test-create-soils.R: -------------------------------------------------------------------------------- 1 | test_that("create_soils returns appropriate error", { 2 | expect_snapshot_error( 3 | create_soils() 4 | ) 5 | }) 6 | -------------------------------------------------------------------------------- /inst/templates/english/resources/word-template.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/inst/templates/english/resources/word-template.docx -------------------------------------------------------------------------------- /inst/templates/spanish/resources/word-template.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WA-Department-of-Agriculture/soils/HEAD/inst/templates/spanish/resources/word-template.docx -------------------------------------------------------------------------------- /R/soils-package.R: -------------------------------------------------------------------------------- 1 | #' @keywords internal 2 | "_PACKAGE" 3 | 4 | ## usethis namespace: start 5 | #' @importFrom quarto quarto_render 6 | #' @importFrom knitr include_graphics 7 | ## usethis namespace: end 8 | NULL 9 | 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | .Rdata 6 | .httr-oauth 7 | .DS_Store 8 | /inst/figure_output/ 9 | *.docx 10 | !*word-template.docx 11 | docs 12 | inst/doc 13 | /doc/ 14 | /Meta/ 15 | scrap.R 16 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # soils 1.0.1 2 | 3 | - Pre-calculate zoom for the static map to fix issue when there are less than 4 | 4 tiles (WA-Department-of-Agriculture/dirt-data-reports#110) and switch to 5 | World Imagery instead of Street Map. 6 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/create-soils.md: -------------------------------------------------------------------------------- 1 | # create_soils returns appropriate error 2 | 3 | ! `path` must be provided. 4 | i Where do you want to create this project? 5 | i For example, `create_soils(path = 'path/to/my/directory')`. 6 | 7 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^soils\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^LICENSE\.md$ 4 | ^README\.Rmd$ 5 | ^data-raw 6 | example_reports 7 | figure_output 8 | ^_pkgdown\.yml$ 9 | ^docs$ 10 | ^pkgdown$ 11 | ^\.github$ 12 | ^vignettes/articles$ 13 | ^doc$ 14 | ^Meta$ 15 | review 16 | scrap.R 17 | figures 18 | -------------------------------------------------------------------------------- /inst/rstudio/templates/project/create_soils_project.dcf: -------------------------------------------------------------------------------- 1 | Title: Quarto Soil Health Report 2 | Binding: create_soils_gui 3 | OpenFiles: 01_producer-report.qmd, R/render-reports.R 4 | Icon: logo.png 5 | 6 | Parameter: template 7 | Widget: SelectInput 8 | Label: Template Type 9 | Fields: English, Spanish 10 | Default: English 11 | -------------------------------------------------------------------------------- /R/globals.R: -------------------------------------------------------------------------------- 1 | utils::globalVariables(c( 2 | "abbr", 3 | "abbr_unit", 4 | "angle", 5 | "category", 6 | "clay", 7 | "dummy", 8 | "Field or Average", 9 | "field_id", 10 | "headers", 11 | "label", 12 | "measurement_group", 13 | "n", 14 | "sample_id", 15 | "sampleLabel", 16 | "sand", 17 | "silt", 18 | "tables", 19 | "texture", 20 | "unit", 21 | "value" 22 | )) 23 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | # This file is part of the standard setup for testthat. 2 | # It is recommended that you do not modify it. 3 | # 4 | # Where should you do additional test configuration? 5 | # Learn more about the roles of various files in: 6 | # * https://r-pkgs.org/testing-design.html#sec-tests-files-overview 7 | # * https://testthat.r-lib.org/articles/special-files.html 8 | 9 | library(testthat) 10 | library(soils) 11 | 12 | test_check("soils") 13 | -------------------------------------------------------------------------------- /man/calculate_mode.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/helpers.R 3 | \name{calculate_mode} 4 | \alias{calculate_mode} 5 | \title{Calculate the mode of categorical variable} 6 | \usage{ 7 | calculate_mode(x) 8 | } 9 | \arguments{ 10 | \item{x}{Character vector to calculate mode from.} 11 | } 12 | \value{ 13 | The value that occurred most often. 14 | } 15 | \description{ 16 | Calculate the mode of categorical variable 17 | } 18 | \examples{ 19 | calculate_mode(washi_data$crop) 20 | 21 | } 22 | -------------------------------------------------------------------------------- /man/summarize_by_project.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/helpers.R 3 | \name{summarize_by_project} 4 | \alias{summarize_by_project} 5 | \title{Summarize samples across the project} 6 | \usage{ 7 | summarize_by_project(results_long) 8 | } 9 | \arguments{ 10 | \item{results_long}{Dataframe in tidy, long format with columns: \code{sample_id}, 11 | \code{texture}, \code{measurement_group}, \code{abbr}, \code{value}.} 12 | } 13 | \description{ 14 | Summarize samples across the project 15 | } 16 | -------------------------------------------------------------------------------- /soils.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: No 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | LineEndingConversion: Posix 18 | 19 | BuildType: Package 20 | PackageUseDevtools: Yes 21 | PackageInstallArgs: --no-multiarch --with-keep.source 22 | PackageRoxygenize: rd,collate,namespace 23 | 24 | MarkdownCanonical: Yes 25 | -------------------------------------------------------------------------------- /inst/templates/english/08_looking-forward.qmd: -------------------------------------------------------------------------------- 1 | \[EDIT: SUMMARY INFORMATION AND A CALL TO ACTION\] *Consider describing how this 2 | data will be used. Are you building decision support tools? Publications? Will 3 | you be speaking at upcoming field days or conferences about this work? Soils 4 | data can be confusing... let your audience know that this is just the start of 5 | the conversation! Thank participating producers once again.* 6 | 7 | ![](https://raw.githack.com/WA-Department-of-Agriculture/soils/main/figures/soil.png){width="4in" 8 | fig-alt="Photo of soil in hands."} 9 | 10 | -------------------------------------------------------------------------------- /man/get_table_headers.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/helpers.R 3 | \name{get_table_headers} 4 | \alias{get_table_headers} 5 | \title{Get table headers for flextable} 6 | \usage{ 7 | get_table_headers(dictionary, group) 8 | } 9 | \arguments{ 10 | \item{dictionary}{Dataframe containing columns \code{measurement_group}, \code{abbr}, 11 | \code{unit}.} 12 | 13 | \item{group}{Character \code{measurement_group} value.} 14 | } 15 | \description{ 16 | This function uses the data dictionary to create a new dataframe of the 17 | abbreviations and units for each measurement group for flextable 18 | } 19 | -------------------------------------------------------------------------------- /man/pull_unique.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/helpers.R 3 | \name{pull_unique} 4 | \alias{pull_unique} 5 | \title{Pull unique values from one column of dataframe} 6 | \usage{ 7 | pull_unique(df, target) 8 | } 9 | \arguments{ 10 | \item{df}{Dataframe with column to extract unique values from.} 11 | 12 | \item{target}{Variable to pull unique vector of (i.e. crop or 13 | county).} 14 | } 15 | \value{ 16 | Vector of unique values from target column. 17 | } 18 | \description{ 19 | Pull unique values from one column of dataframe 20 | } 21 | \examples{ 22 | washi_data |> 23 | pull_unique(crop) 24 | 25 | } 26 | -------------------------------------------------------------------------------- /man/soils_example.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{soils_example} 4 | \alias{soils_example} 5 | \title{Get path to example data} 6 | \source{ 7 | Adapted from \code{readxl::readxl_example()}. 8 | } 9 | \usage{ 10 | soils_example(file = NULL) 11 | } 12 | \arguments{ 13 | \item{file}{Name of file. If \code{NULL}, the example files will be listed.} 14 | } 15 | \description{ 16 | \code{soils} comes bundled with some example files in its \code{inst/extdata} 17 | directory. This function make them easy to access. 18 | } 19 | \examples{ 20 | soils_example() 21 | 22 | soils_example("df_plot.RDS") 23 | } 24 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(add_legend) 4 | export(add_texture_points) 5 | export(calculate_mode) 6 | export(convert_ggiraph) 7 | export(create_soils) 8 | export(format_ft_colors) 9 | export(get_table_headers) 10 | export(make_ft) 11 | export(make_leaflet) 12 | export(make_strip_plot) 13 | export(make_texture_triangle) 14 | export(prep_for_map) 15 | export(pull_unique) 16 | export(set_scales) 17 | export(soils_example) 18 | export(style_ft) 19 | export(summarize_by_project) 20 | export(summarize_by_var) 21 | export(theme_facet_strip) 22 | export(unit_hline) 23 | importFrom(knitr,include_graphics) 24 | importFrom(quarto,quarto_render) 25 | -------------------------------------------------------------------------------- /man/get_n_texture_by_var.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/helpers.R 3 | \name{get_n_texture_by_var} 4 | \alias{get_n_texture_by_var} 5 | \title{Calculate n samples and most frequent texture by a grouping variable} 6 | \usage{ 7 | get_n_texture_by_var(results_long, producer_info, var) 8 | } 9 | \arguments{ 10 | \item{results_long}{Dataframe in tidy, long format with columns: \code{sample_id}, 11 | \code{texture}.} 12 | 13 | \item{producer_info}{Vector of producer's values for the grouping variable.} 14 | 15 | \item{var}{Variable to group and summarize by.} 16 | } 17 | \description{ 18 | This function is used in \code{summarize_by_var}. 19 | } 20 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /inst/templates/english/09_acknowledgement.qmd: -------------------------------------------------------------------------------- 1 | This report was generated using the [{soils} R 2 | package](https://wa-department-of-agriculture.github.io/soils/). {soils} was 3 | developed by the Washington State Department of Agriculture and Washington State 4 | University, as part of the Washington Soil Health Initiative. Text and figures 5 | were adapted from [WSU Extension publication #FS378E Soil Health in Washington 6 | Vineyards](https://pubs.extension.wsu.edu/soil-health-in-washington-vineyards). 7 | Learn more about {soils} in this [blog 8 | post](https://washingtonsoilhealthinitiative.com/2024/03/soils-an-r-package-for-soil-health-reporting/) 9 | or this [webinar](https://youtu.be/_8m7fTjSEOk?si=ikrCASdchiB6rDC2). 10 | -------------------------------------------------------------------------------- /man/summarize_by_var.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/helpers.R 3 | \name{summarize_by_var} 4 | \alias{summarize_by_var} 5 | \title{Summarize producer's samples with averages by grouping variable} 6 | \usage{ 7 | summarize_by_var(results_long, producer_samples, var) 8 | } 9 | \arguments{ 10 | \item{results_long}{Dataframe in tidy, long format with columns: \code{sample_id}, 11 | \code{texture}, \code{measurement_group}, \code{abbr}, \code{value}.} 12 | 13 | \item{producer_samples}{Dataframe in tidy, long format with columns: 14 | \code{measurement_group}, \code{abbr}, \code{value}.} 15 | 16 | \item{var}{Variable to summarize by.} 17 | } 18 | \description{ 19 | Summarize producer's samples with averages by grouping variable 20 | } 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/documentation-improvement.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Documentation improvement 3 | about: Suggest an idea for better documentation 4 | title: '' 5 | labels: documentation 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Are you suggesting new documentation or improvements to existing documentation?** 11 | - [ ] New documentation 12 | - [ ] Existing documentation 13 | 14 | **How did this request for better documentation come about?** 15 | Did you get an error or maybe you couldn't find how to do something? 16 | 17 | **Describe what you'd like to see and where you'd like to see it (i.e. function help, README, pkgdown website, etc.)** 18 | A clear and concise description of what you'd like (better) explained. 19 | 20 | **Additional context** 21 | Add any other context or screenshots about the feature request here. 22 | -------------------------------------------------------------------------------- /inst/templates/spanish/09_acknowledgement.qmd: -------------------------------------------------------------------------------- 1 | La plantilla de informe sobre la salud del suelo utilizada para generar este 2 | informe fue desarrollada por el Departamento de Agricultura del Estado de 3 | Washington y la Universidad Estatal de Washington (WSU) como parte de la 4 | Iniciativa sobre la Salud del Suelo de Washington. El contenido y las figuras 5 | fueron adaptadas de la publicación de estension universitaria de el estado de 6 | Washington [#FS378E Soil Health in Washington 7 | Vineyards](https://pubs.extension.wsu.edu/soil-health-in-washington-vineyards). 8 | 9 | El texto del reporte y las imágenes fueron traducidas por Erica Tello, Eber 10 | Rivera, y Kate Smith con WSU Food Systems y Skagit County Extension como parte 11 | del programa de USDA NRCS Innovación en la conservación, dirigido por Viva Farms 12 | (grant number NR22-13G004). 13 | 14 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Please complete the following information:** 27 | - OS: [e.g. Windows or Mac] 28 | - R Version (run `version$version.string` in console): [e.g. 4.3.1 (2023-06-16 ucrt)] 29 | - RStudio Version (RStudio > Help > About RStudio): [e.g. 2023.06.2] 30 | 31 | **Additional context** 32 | Add any other context about the problem here. 33 | -------------------------------------------------------------------------------- /man/make_leaflet.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/map.R 3 | \name{make_leaflet} 4 | \alias{make_leaflet} 5 | \title{Make leaflet map} 6 | \source{ 7 | JavaScript code adapted from 8 | \href{https://github.com/bhaskarvk/leaflet.extras/tree/master}{leaflet.extras}. 9 | } 10 | \usage{ 11 | make_leaflet(df, primary_color = "#a60f2d") 12 | } 13 | \arguments{ 14 | \item{df}{Dataframe containing columns: \code{longitude}, \code{latitude}, \code{label}, 15 | \code{popup}. See \code{prep_for_map()} for details.} 16 | 17 | \item{primary_color}{Color of points. Defaults to WaSHI red.} 18 | } 19 | \value{ 20 | Leaflet map. 21 | } 22 | \description{ 23 | Make leaflet map 24 | } 25 | \examples{ 26 | gis_df <- washi_data |> 27 | dplyr::distinct(latitude, longitude, .keep_all = TRUE) |> 28 | head(3) |> 29 | prep_for_map(label_heading = field_name, label_body = crop) 30 | 31 | dplyr::glimpse(gis_df) 32 | 33 | # Make leaflet 34 | make_leaflet(gis_df) 35 | } 36 | -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | citHeader("To cite {soils} in publications, please use:") 2 | 3 | bibentry( 4 | bibtype = "Article", 5 | title = "Visualize and Report Soil Health Survey Data with {soils}", 6 | author = c( 7 | as.person("Jadey N Ryan"), 8 | as.person("Molly McIlquham"), 9 | as.person("Kwabena A Sarpong"), 10 | as.person("Leslie Michel"), 11 | as.person("Teal Potter"), 12 | as.person("Deirdre Griffin LaHue"), 13 | as.person("Dani L Gelardi"), 14 | as.person("Washington State Department of Agriculture") 15 | ), 16 | journal = "Washington Soil Health Initiative", 17 | year = "2024", 18 | url = "https://github.com/WA-Department-of-Agriculture/soils", 19 | textVersion = 20 | paste("Ryan JN, McIlquham M, Sarpong KA, Michel LM, Potter TS, Griffin LaHue D, Gelardi DL.", 21 | "2024. Visualize and Report Soil Health Data with {soils}.", 22 | "Washington Soil Health Initiative.", 23 | "https://github.com/WA-Department-of-Agriculture/soils") 24 | ) 25 | -------------------------------------------------------------------------------- /man/prep_for_map.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/map.R 3 | \name{prep_for_map} 4 | \alias{prep_for_map} 5 | \title{Prep data to gis df} 6 | \usage{ 7 | prep_for_map(df, label_heading, label_body) 8 | } 9 | \arguments{ 10 | \item{df}{Dataframe containing columns: \code{longitude}, \code{latitude}, and two 11 | columns with values you want to appear in the map label and popup.} 12 | 13 | \item{label_heading}{Column in \code{df} that you want to appear as the bold point 14 | label on your map, as well as the first line of the popup when the user 15 | clicks a point.} 16 | 17 | \item{label_body}{Column in \code{df} that you want to appear as body text below 18 | the \code{label_heading} in the popup.} 19 | } 20 | \value{ 21 | Dataframe to be input into \code{make_leaflet()}. 22 | } 23 | \description{ 24 | Prep data to gis df 25 | } 26 | \examples{ 27 | washi_data |> 28 | dplyr::distinct(latitude, longitude, .keep_all = TRUE) |> 29 | head(3) |> 30 | prep_for_map(label_heading = field_name, label_body = crop) |> 31 | dplyr::glimpse() 32 | } 33 | -------------------------------------------------------------------------------- /man/washi_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{washi_data} 5 | \alias{washi_data} 6 | \title{Example WaSHI data} 7 | \format{ 8 | \subsection{\code{washi_data} A data frame with 100 rows and 42 columns:}{ 9 | 10 | \describe{ 11 | \item{year}{Year of sample} 12 | \item{sample_id, producer_id, field_id}{Anonymized IDs} 13 | \item{farm_name, field_name}{Anonymized names} 14 | \item{longitude, latitude}{Truncated coordinates} 15 | \item{texture}{Measured soil texture} 16 | \item{other columns}{Column name includes measurement and units; 17 | value is the measurement result} 18 | ... 19 | } 20 | } 21 | } 22 | \source{ 23 | \href{https://washingtonsoilhealthinitiative.com/state-of-the-soils/}{WaSHI State of the Soils} 24 | } 25 | \usage{ 26 | washi_data 27 | } 28 | \description{ 29 | A subset of the Washington Soil Health Initiative (WaSHI) State of the Soils 30 | Assessment anonymized data. This data set presents each sample in its own 31 | row, with columns for each measurement. 32 | } 33 | \keyword{datasets} 34 | -------------------------------------------------------------------------------- /man/create_soils.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/create-soils.R 3 | \name{create_soils} 4 | \alias{create_soils} 5 | \title{Create a project directory for generating soil health reports} 6 | \source{ 7 | Adapted from \code{golem::create_golem()}. 8 | } 9 | \usage{ 10 | create_soils(path, template = "English", overwrite = FALSE, open = TRUE) 11 | } 12 | \arguments{ 13 | \item{path}{Name of project directory to be created.} 14 | 15 | \item{template}{Template type. Either "English" or "Spanish".} 16 | 17 | \item{overwrite}{Boolean. Overwrite the existing project?} 18 | 19 | \item{open}{Boolean. Open the newly created project?} 20 | } 21 | \value{ 22 | A new project directory containing template and resources. 23 | } 24 | \description{ 25 | Creates an RStudio project containing Quarto template and resources (images, 26 | style sheets, render.R script). 27 | } 28 | \examples{ 29 | \dontrun{ 30 | # Create temporary directory 31 | dir <- tempdir() 32 | 33 | # Create soils project 34 | create_soils(dir, overwrite = TRUE) 35 | 36 | # Delete temporary directory 37 | unlink(dir, recursive = TRUE) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2022 Washington State Department of Agriculture 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /man/data_dictionary.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{data_dictionary} 5 | \alias{data_dictionary} 6 | \title{Data dictionary} 7 | \format{ 8 | \subsection{\code{data_dictionary} A data frame with 32 rows and 7 columns.}{ 9 | 10 | \describe{ 11 | \item{measurement_group}{Name to group measurements by} 12 | \item{measurement_group_label}{Label of measurement group to be used as 13 | heading} 14 | \item{column_name}{Name of column in data set, used for joining} 15 | \item{order}{Order of how measurements are presented within each 16 | measurement_group} 17 | \item{abbr}{Abbreviated measurement name for labels} 18 | \item{unit}{Measurement unit} 19 | \item{abbr_unit}{HTML formatted abbreviation with unit for plots and 20 | tables} 21 | ... 22 | } 23 | } 24 | } 25 | \source{ 26 | \href{https://washingtonsoilhealthinitiative.com/state-of-the-soils/}{WaSHI State of the Soils} 27 | } 28 | \usage{ 29 | data_dictionary 30 | } 31 | \description{ 32 | An example data dictionary for the Washington Soil Health Initiative (WaSHI) 33 | State of the Soils Assessment anonymized data. 34 | } 35 | \keyword{datasets} 36 | -------------------------------------------------------------------------------- /man/style_ft.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tables.R 3 | \name{style_ft} 4 | \alias{style_ft} 5 | \title{Style a flextable} 6 | \usage{ 7 | style_ft( 8 | ft, 9 | header_font = "Lato", 10 | body_font = "Poppins", 11 | header_color = "#023B2C", 12 | header_text_color = "white", 13 | border_color = "#3E3D3D" 14 | ) 15 | } 16 | \arguments{ 17 | \item{ft}{Flextable object.} 18 | 19 | \item{header_font}{Font of header text. Defaults to \code{"Lato"}.} 20 | 21 | \item{body_font}{Font of body text. Defaults to \code{"Poppins"}.} 22 | 23 | \item{header_color}{Background color of header cells. Defaults to WaSHI 24 | green.} 25 | 26 | \item{header_text_color}{Color of header text. Defaults to white.} 27 | 28 | \item{border_color}{Color of border lines. Defaults to WaSHI gray.} 29 | } 30 | \value{ 31 | Styled flextable object. 32 | } 33 | \description{ 34 | Style a flextable 35 | } 36 | \examples{ 37 | # Read in wrangled example table data 38 | tables_path <- soils_example("tables.RDS") 39 | tables <- readRDS(tables_path) 40 | 41 | # Make the table 42 | ft <- flextable::flextable(tables$biological) 43 | ft 44 | 45 | # Style the table 46 | style_ft(ft) 47 | } 48 | -------------------------------------------------------------------------------- /man/format_ft_colors.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tables.R 3 | \name{format_ft_colors} 4 | \alias{format_ft_colors} 5 | \title{Conditional formatting of flextable background cell colors} 6 | \usage{ 7 | format_ft_colors( 8 | ft, 9 | lighter_color = "#F2F0E6", 10 | darker_color = "#ccc29c", 11 | language = "English" 12 | ) 13 | } 14 | \arguments{ 15 | \item{ft}{Flextable object} 16 | 17 | \item{lighter_color}{Lighter background color. Defaults to WaSHI cream.} 18 | 19 | \item{darker_color}{Darker background color. Defaults to WaSHI tan.} 20 | 21 | \item{language}{Language of the footnote. "English" (default) or "Spanish".} 22 | } 23 | \description{ 24 | Color the background cells based on how the value compares to the project 25 | average. The project average must be the last row of the table. A footnote is 26 | added to the table describing what the dark and light colors mean. 27 | } 28 | \examples{ 29 | # Read in wrangled example table data 30 | tables_path <- soils_example("tables.RDS") 31 | tables <- readRDS(tables_path) 32 | 33 | # Make the table 34 | ft <- flextable::flextable(tables$biological) 35 | ft 36 | 37 | # Conditionally format background cell colors 38 | format_ft_colors(ft) 39 | } 40 | -------------------------------------------------------------------------------- /R/utils.R: -------------------------------------------------------------------------------- 1 | #' Get path to example data 2 | #' 3 | #' `soils` comes bundled with some example files in its `inst/extdata` 4 | #' directory. This function make them easy to access. 5 | #' 6 | #' @param file Name of file. If `NULL`, the example files will be listed. 7 | #' @source Adapted from `readxl::readxl_example()`. 8 | #' 9 | #' @export 10 | #' 11 | #' @examples 12 | #' soils_example() 13 | #' 14 | #' soils_example("df_plot.RDS") 15 | soils_example <- function(file = NULL) { 16 | if (is.null(file)) { 17 | dir(system.file("extdata", package = "soils")) 18 | } else { 19 | system.file( 20 | "extdata", file, 21 | package = "soils", 22 | mustWork = TRUE 23 | ) 24 | } 25 | } 26 | 27 | # Below functions from 28 | # https://github.com/ThinkR-open/golem/blob/365a5cc303b189973abab0dd375c64be79bcf74a/R/utils.R 29 | 30 | soils_sys <- function( 31 | ..., 32 | lib.loc = NULL, 33 | mustWork = FALSE 34 | ) { 35 | system.file( 36 | ..., 37 | package = "soils", 38 | lib.loc = lib.loc, 39 | mustWork = mustWork 40 | ) 41 | } 42 | 43 | cat_green_tick <- function(...) { 44 | cli::cat_bullet( 45 | ..., 46 | bullet = "tick", 47 | bullet_col = "green" 48 | ) 49 | } 50 | 51 | cat_red_bullet <- function(...) { 52 | cli::cat_bullet( 53 | ..., 54 | bullet = "bullet", 55 | bullet_col = "red" 56 | ) 57 | } 58 | -------------------------------------------------------------------------------- /man/make_texture_triangle.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/texture-triangle.R 3 | \name{make_texture_triangle} 4 | \alias{make_texture_triangle} 5 | \title{Make a textural class triangle} 6 | \source{ 7 | Adapted from {plotrix}: 8 | \url{https://github.com/plotrix/plotrix/blob/0d4c2b065e2c2d327358ac8cdc0b0d46b89bea7f/R/soil.texture.R} 9 | } 10 | \usage{ 11 | make_texture_triangle( 12 | body_font = "Poppins", 13 | show_names = TRUE, 14 | show_lines = TRUE, 15 | show_grid = FALSE 16 | ) 17 | } 18 | \arguments{ 19 | \item{body_font}{Font family to use throughout plot. Defaults to \code{"Poppins"}.} 20 | 21 | \item{show_names}{Boolean. Defaults to \code{TRUE} to show USDA textural class 22 | names.} 23 | 24 | \item{show_lines}{Boolean. Defaults to \code{TRUE} to show boundaries of USDA 25 | textural classes.} 26 | 27 | \item{show_grid}{Boolean. Defaults to \code{FALSE} to hide grid lines at each 10 28 | level of each soil component.} 29 | } 30 | \value{ 31 | Opens the graphics device with a triangle plot containing USDA 32 | textural classes. 33 | } 34 | \description{ 35 | Make a texture triangle with USDA textural classes. 36 | } 37 | \examples{ 38 | # Note the text appears squished in this example since the width, height, 39 | # and resolution have been optimized to print the figure 6 in wide in the 40 | # report. 41 | 42 | make_texture_triangle(body_font = "sans") 43 | } 44 | -------------------------------------------------------------------------------- /inst/templates/spanish/08_looking-forward.qmd: -------------------------------------------------------------------------------- 1 | \[EDIT: SUMMARY INFORMATION AND A CALL TO ACTION\] *Consider describing how this 2 | data will be used. Are you building decision support tools? Publications? Will 3 | you be speaking at upcoming field days or conferences about this work? Soils 4 | data can be confusing... let your audience know that this is just the start of 5 | the conversation! Thank participating producers once again. See the example 6 | below.* 7 | 8 | Esperamos que este informe preliminar sobre la salud del suelo le resulte 9 | informativo. Recuerde que este es el comienzo de un proyecto a largo plazo. En 10 | última instancia, estos datos se utilizarán con la encuesta de gestión para 11 | comprender mejor cómo los indicadores de salud del suelo están vinculados a las 12 | funciones del suelo, como la supresión de enfermedades, el mantenimiento del 13 | rendimiento y el secuestro de carbono. Sus datos son fundamentales para 14 | desarrollar herramientas de apoyo a la toma de decisiones específicas de 15 | cultivos y regiones, actualmente en desarrollo. Para obtener actualizaciones del 16 | proyecto, oportunidades de financiamiento o para participar más, [visite el 17 | sitio web de la Iniciativa de Salud del Suelo de 18 | Washington](https://washingtonsoilhealthinitiative.com/). 19 | 20 | ![](https://raw.githack.com/WA-Department-of-Agriculture/soils/main/figures/soil.png){width="4in" 21 | fig-alt="Foto de tierra en las manos."} 22 | -------------------------------------------------------------------------------- /inst/templates/english/data/data-dictionary.csv: -------------------------------------------------------------------------------- 1 | measurement_group,column_name,abbr,unit 2 | Physical,texture,Texture, 3 | Physical,sand_percent,Sand,% 4 | Physical,silt_percent,Silt,% 5 | Physical,clay_percent,Clay,% 6 | Physical,bd_g_cm3,Bulk Density,g/cm³ 7 | Physical,wsa_percent,Agg. Stability,% 8 | Physical,whc_in_ft,WHC,in/ft 9 | Biological,om_percent,Organic Matter,% 10 | Biological,min_c_96hr_mg_c_kg_day,Min C,mg/kg/day 11 | Biological,poxc_mg_kg,POXC,ppm 12 | Biological,pmn_lb_ac,PMN,lb/ac 13 | Biological,ace_g_protein_kg_soil,ACE Protein,g/kg 14 | Chemical,ph,pH, 15 | Chemical,ec_mmhos_cm,EC,mmhos/cm 16 | Chemical,cec_meq_100g,CEC,cmolc/kg 17 | Chemical,total_c_percent,Total C,% 18 | Chemical,toc_percent,TOC,% 19 | Chemical,inorganic_c_percent,Inorganic C,% 20 | Plant Essential Macro Nutrients,total_n_percent,Total N,% 21 | Plant Essential Macro Nutrients,no3_n_mg_kg,NO₃-N,ppm 22 | Plant Essential Macro Nutrients,nh4_n_mg_kg,NH₄-N,ppm 23 | Plant Essential Macro Nutrients,p_olsen_mg_kg,P,ppm 24 | Plant Essential Macro Nutrients,k_mg_kg,K,ppm 25 | Plant Essential Macro Nutrients,ca_mg_kg,Ca,ppm 26 | Plant Essential Macro Nutrients,mg_mg_kg,Mg,ppm 27 | Plant Essential Macro Nutrients,s_mg_kg,S,ppm 28 | Plant Essential Micro Nutrients,b_mg_kg,B,ppm 29 | Plant Essential Micro Nutrients,fe_mg_kg,Fe,ppm 30 | Plant Essential Micro Nutrients,mn_mg_kg,Mn,ppm 31 | Plant Essential Micro Nutrients,cu_mg_kg,Cu,ppm 32 | Plant Essential Micro Nutrients,zn_mg_kg,Zn,ppm 33 | Plant Essential Micro Nutrients,na_mg_kg,Na,ppm 34 | -------------------------------------------------------------------------------- /.github/workflows/pkgdown.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | release: 9 | types: [published] 10 | workflow_dispatch: 11 | 12 | name: pkgdown 13 | 14 | jobs: 15 | pkgdown: 16 | runs-on: ubuntu-latest 17 | # Only restrict concurrency for non-PR jobs 18 | concurrency: 19 | group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} 20 | env: 21 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 22 | permissions: 23 | contents: write 24 | steps: 25 | - uses: actions/checkout@v4 26 | 27 | - uses: r-lib/actions/setup-pandoc@v2 28 | 29 | - uses: r-lib/actions/setup-r@v2 30 | with: 31 | use-public-rspm: true 32 | 33 | - uses: r-lib/actions/setup-r-dependencies@v2 34 | with: 35 | extra-packages: r-lib/pkgdown, local::. 36 | needs: website 37 | 38 | - name: Build site 39 | run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) 40 | shell: Rscript {0} 41 | 42 | - name: Deploy to GitHub pages 🚀 43 | if: github.event_name != 'pull_request' 44 | uses: JamesIves/github-pages-deploy-action@v4.5.0 45 | with: 46 | clean: false 47 | branch: gh-pages 48 | folder: docs 49 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | 9 | name: R-CMD-check 10 | 11 | jobs: 12 | R-CMD-check: 13 | runs-on: ${{ matrix.config.os }} 14 | 15 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 16 | 17 | strategy: 18 | fail-fast: false 19 | matrix: 20 | config: 21 | - {os: macos-latest, r: 'release'} 22 | - {os: windows-latest, r: 'release'} 23 | - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} 24 | - {os: ubuntu-latest, r: 'release'} 25 | - {os: ubuntu-latest, r: 'oldrel-1'} 26 | 27 | env: 28 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 29 | R_KEEP_PKG_SOURCE: yes 30 | 31 | steps: 32 | - uses: actions/checkout@v3 33 | 34 | - uses: r-lib/actions/setup-pandoc@v2 35 | 36 | - uses: r-lib/actions/setup-r@v2 37 | with: 38 | r-version: ${{ matrix.config.r }} 39 | http-user-agent: ${{ matrix.config.http-user-agent }} 40 | use-public-rspm: true 41 | 42 | - uses: r-lib/actions/setup-r-dependencies@v2 43 | with: 44 | extra-packages: any::rcmdcheck 45 | needs: check 46 | 47 | - uses: r-lib/actions/check-r-package@v2 48 | with: 49 | upload-snapshots: true 50 | -------------------------------------------------------------------------------- /man/make_ft.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tables.R 3 | \name{make_ft} 4 | \alias{make_ft} 5 | \title{Make a flextable with column names from another dataframe} 6 | \usage{ 7 | make_ft(table, header) 8 | } 9 | \arguments{ 10 | \item{table}{A dataframe with the contents of the desired flextable output.} 11 | 12 | \item{header}{Another dataframe with three columns: 13 | \itemize{ 14 | \item First column contains what the top header row should be. In our template, 15 | this is the abbreviation of the measurement (i.e. \verb{Organic Matter}). 16 | \item Second column, called \code{"key"}, contains the join key. In our template, 17 | this is the same as the first column. 18 | \item Third column contains the second header row. In our template, this is 19 | the unit (i.e. \verb{\%}). 20 | }} 21 | } 22 | \value{ 23 | Formatted flextable object. 24 | } 25 | \description{ 26 | Make a flextable with column names from another dataframe 27 | } 28 | \examples{ 29 | # Read in wrangled table data 30 | headers_path <- soils_example("headers.RDS") 31 | headers <- readRDS(headers_path) 32 | 33 | tables_path <- soils_example("tables.RDS") 34 | tables <- readRDS(tables_path) 35 | 36 | # Input dataframes 37 | headers$chemical 38 | 39 | tables$chemical 40 | 41 | # Make the flextable 42 | make_ft( 43 | table = tables$chemical, 44 | header = headers$chemical 45 | ) |> 46 | # Style the flextable 47 | style_ft() |> 48 | # Add the white line under the columns with the same units 49 | unit_hline(header = headers$chemical) 50 | 51 | } 52 | -------------------------------------------------------------------------------- /man/soils-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/soils-package.R 3 | \docType{package} 4 | \name{soils-package} 5 | \alias{soils} 6 | \alias{soils-package} 7 | \title{soils: Visualize and Report Soil Health Data} 8 | \description{ 9 | \if{html}{\figure{logo.png}{options: style='float: right' alt='logo' width='120'}} 10 | 11 | Collection of soil health data visualization and reporting tools, including a RStudio project template with everything you need to generate custom HTML and Microsoft Word reports for each participant in your soil health sampling project. 12 | } 13 | \seealso{ 14 | Useful links: 15 | \itemize{ 16 | \item \url{https://github.com/WA-Department-of-Agriculture/soils} 17 | \item \url{https://wa-department-of-agriculture.github.io/soils/} 18 | \item Report bugs at \url{https://github.com/WA-Department-of-Agriculture/soils/issues} 19 | } 20 | 21 | } 22 | \author{ 23 | \strong{Maintainer}: Jadey N Ryan \email{jryan@agr.wa.gov} (\href{https://orcid.org/0009-0004-5998-4697}{ORCID}) 24 | 25 | Authors: 26 | \itemize{ 27 | \item Molly McIlquham (\href{https://orcid.org/0000-0002-0152-969X}{ORCID}) 28 | \item Kwabena A Sarpong 29 | \item Leslie M Michel 30 | \item Teal S Potter (\href{https://orcid.org/0000-0002-4884-2720}{ORCID}) 31 | \item Deirdre Griffin LaHue (\href{https://orcid.org/0000-0001-5711-797X}{ORCID}) 32 | \item Dani L Gelardi (\href{https://orcid.org/0000-0002-5015-8119}{ORCID}) 33 | } 34 | 35 | Other contributors: 36 | \itemize{ 37 | \item Washington State Department of Agriculture [copyright holder, funder] 38 | } 39 | 40 | } 41 | \keyword{internal} 42 | -------------------------------------------------------------------------------- /man/unit_hline.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tables.R 3 | \name{unit_hline} 4 | \alias{unit_hline} 5 | \title{Add bottom border to specific columns in flextable} 6 | \usage{ 7 | unit_hline(ft, header) 8 | } 9 | \arguments{ 10 | \item{ft}{flextable object} 11 | 12 | \item{header}{Another dataframe with three columns: 13 | \itemize{ 14 | \item First column contains what the top header row should be. In our template, 15 | this is the abbreviation of the measurement (i.e. \verb{Organic Matter}). 16 | \item Second column, called \code{"key"}, contains the join key. In our template, 17 | this is the same as the first column. 18 | \item Third column contains the second header row. In our template, this is 19 | the unit (i.e. \verb{\%}). 20 | }} 21 | } 22 | \value{ 23 | Flextable object with bottom borders added. 24 | } 25 | \description{ 26 | Use when columns with the same units are merged together to add a bottom 27 | border to make it more obvious those columns share units. 28 | } 29 | \examples{ 30 | # Read in wrangled table data 31 | headers_path <- soils_example("headers.RDS") 32 | headers <- readRDS(headers_path) 33 | 34 | tables_path <- soils_example("tables.RDS") 35 | tables <- readRDS(tables_path) 36 | 37 | # Input dataframes 38 | headers$chemical 39 | 40 | tables$chemical 41 | 42 | # Make the flextable 43 | make_ft( 44 | table = tables$chemical, 45 | header = headers$chemical 46 | ) |> 47 | # Style the flextable 48 | style_ft() |> 49 | # Add the white line under the columns with the same units 50 | unit_hline(header = headers$chemical) 51 | 52 | # Example without `unit_hline()` 53 | make_ft( 54 | table = tables$chemical, 55 | header = headers$chemical 56 | ) |> 57 | # Style the flextable 58 | style_ft() 59 | } 60 | -------------------------------------------------------------------------------- /pkgdown/extra.css: -------------------------------------------------------------------------------- 1 | :root { 2 | --green: #023B2C; 3 | --blue: #335C67; 4 | --gray: #3E3D3D; 5 | --red: #A60F2D; 6 | --cream: #F2F0E6; 7 | --off-white: #FAF9F6; 8 | --off-black: #191919; 9 | } 10 | 11 | h2, .h2, h1, .h1 { 12 | font-weight: bold; 13 | color: var(--green); 14 | } 15 | 16 | h6, .h6, h5, .h5, h4, .h4, h3, .h3 { 17 | font-weight: bold; 18 | color: var(--blue); 19 | } 20 | 21 | a { 22 | color: var(--red); 23 | } 24 | 25 | a:hover { 26 | color: var(--red); 27 | filter: brightness(100%); 28 | } 29 | 30 | .navbar-nav .nav-item>.nav-link { 31 | margin-left: .2em; 32 | margin-right: .2em; 33 | } 34 | 35 | .navbar-dark .navbar-nav .nav-item>.nav-link:hover, .navbar-light .navbar-nav .nav-item>.nav-link:hover { 36 | background: rgb(139 206 188 / 20%); 37 | color: var(--off-white); 38 | } 39 | 40 | .navbar-dark .navbar-nav .active>.nav-link { 41 | background: rgb(139 206 188 / 30%); 42 | color: var(--off-white) !important; 43 | } 44 | 45 | .navbar-dark input[type="search"] { 46 | background-color: var(--off-white); 47 | color: var(--off-black); 48 | } 49 | 50 | .dropdown-menu { 51 | --bs-dropdown-divider-bg: var(--gray); 52 | background-color: var(--cream); 53 | color: var(--off-black); 54 | } 55 | 56 | .dropdown-item { 57 | background-color: var(--cream); 58 | color: var(--off-black); 59 | } 60 | 61 | .dropdown-item:hover, .dropdown-item:focus { 62 | color: var(--off-white); 63 | background-color: var(--green); 64 | } 65 | 66 | .iframe { 67 | aspect-ratio: 16 / 9; 68 | width: 100%; 69 | height: 100%; 70 | } 71 | 72 | .caption { 73 | font-style: italic; 74 | } 75 | 76 | .text-muted { 77 | color: var(--off-white) !important; 78 | } 79 | 80 | a.footnote-ref { 81 | text-decoration: none; 82 | } 83 | -------------------------------------------------------------------------------- /inst/templates/spanish/data/data-dictionary.csv: -------------------------------------------------------------------------------- 1 | measurement_group,column_name,abbr,unit 2 | Mediciones físicas,texture,Textura, 3 | Mediciones físicas,sand_percent,Arena,% 4 | Mediciones físicas,silt_percent,Limo,% 5 | Mediciones físicas,clay_percent,Arcilla,% 6 | Mediciones físicas,bd_g_cm3,Densidad aparente,g/cm³ 7 | Mediciones físicas,wsa_percent,Estabilidad de agregados,% 8 | Mediciones físicas,whc_in_ft,WHC,in/ft 9 | Mediciones biológicas,om_percent,Materia organica,% 10 | Mediciones biológicas,min_c_96hr_mg_c_kg_day,Min C,mg/kg/day 11 | Mediciones biológicas,poxc_mg_kg,POXC,ppm 12 | Mediciones biológicas,pmn_lb_ac,PMN,lb/ac 13 | Mediciones biológicas,ace_g_protein_kg_soil,ACE Proteina,g/kg 14 | Mediciones químicas,ph,pH, 15 | Mediciones químicas,ec_mmhos_cm,EC,mmhos/cm 16 | Mediciones químicas,cec_meq_100g,CEC,cmolc/kg 17 | Mediciones químicas,total_c_percent,Total C,% 18 | Mediciones químicas,toc_percent,TOC,% 19 | Mediciones químicas,inorganic_c_percent,Inorganic C,% 20 | Macronutrientes esenciales para plantas,total_n_percent,Total N,% 21 | Macronutrientes esenciales para plantas,no3_n_mg_kg,NO₃-N,ppm 22 | Macronutrientes esenciales para plantas,nh4_n_mg_kg,NH₄-N,ppm 23 | Macronutrientes esenciales para plantas,p_olsen_mg_kg,P,ppm 24 | Macronutrientes esenciales para plantas,k_mg_kg,K,ppm 25 | Macronutrientes esenciales para plantas,ca_mg_kg,Ca,ppm 26 | Macronutrientes esenciales para plantas,mg_mg_kg,Mg,ppm 27 | Macronutrientes esenciales para plantas,s_mg_kg,S,ppm 28 | Micronutriente es esenciales para plantas,b_mg_kg,B,ppm 29 | Micronutriente es esenciales para plantas,fe_mg_kg,Fe,ppm 30 | Micronutriente es esenciales para plantas,mn_mg_kg,Mn,ppm 31 | Micronutriente es esenciales para plantas,cu_mg_kg,Cu,ppm 32 | Micronutriente es esenciales para plantas,zn_mg_kg,Zn,ppm 33 | Micronutriente es esenciales para plantas,na_mg_kg,Na,ppm 34 | -------------------------------------------------------------------------------- /R/data.R: -------------------------------------------------------------------------------- 1 | #' Example WaSHI data 2 | #' 3 | #' A subset of the Washington Soil Health Initiative (WaSHI) State of the Soils 4 | #' Assessment anonymized data. This data set presents each sample in its own 5 | #' row, with columns for each measurement. 6 | #' 7 | #' @format ## `washi_data` A data frame with 100 rows and 42 columns: 8 | #' \describe{ 9 | #' \item{year}{Year of sample} 10 | #' \item{sample_id, producer_id, field_id}{Anonymized IDs} 11 | #' \item{farm_name, field_name}{Anonymized names} 12 | #' \item{longitude, latitude}{Truncated coordinates} 13 | #' \item{texture}{Measured soil texture} 14 | #' \item{other columns}{Column name includes measurement and units; 15 | #' value is the measurement result} 16 | #' ... 17 | #' } 18 | #' @source 19 | #' [WaSHI State of the Soils](https://washingtonsoilhealthinitiative.com/state-of-the-soils/) 20 | "washi_data" 21 | 22 | #' Data dictionary 23 | #' 24 | #' An example data dictionary for the Washington Soil Health Initiative (WaSHI) 25 | #' State of the Soils Assessment anonymized data. 26 | #' 27 | #' @format ## `data_dictionary` A data frame with 32 rows and 7 columns. 28 | #' \describe{ 29 | #' \item{measurement_group}{Name to group measurements by} 30 | #' \item{measurement_group_label}{Label of measurement group to be used as 31 | #' heading} 32 | #' \item{column_name}{Name of column in data set, used for joining} 33 | #' \item{order}{Order of how measurements are presented within each 34 | #' measurement_group} 35 | #' \item{abbr}{Abbreviated measurement name for labels} 36 | #' \item{unit}{Measurement unit} 37 | #' \item{abbr_unit}{HTML formatted abbreviation with unit for plots and 38 | #' tables} 39 | #' ... 40 | #' } 41 | #' @source 42 | #' [WaSHI State of the Soils](https://washingtonsoilhealthinitiative.com/state-of-the-soils/) 43 | "data_dictionary" 44 | -------------------------------------------------------------------------------- /inst/templates/english/02_section-template.qmd: -------------------------------------------------------------------------------- 1 | ```{r} 2 | # If the report fails to render at the `create-measurement-group-sections` chunk 3 | # in `01_producer-report.qmd`, run all chunks above to load the data in your 4 | # environment. Then uncomment this group assignment and run each code chunk in 5 | # this file interactively to troubleshoot. 6 | 7 | # group <- "Physical" 8 | ``` 9 | 10 | ```{r} 11 | # Get path of measurement group image 12 | image_path <- glue::glue("images/{group}.png") 13 | 14 | # Insert image into header if image exists for that measurement group 15 | image <- ifelse( 16 | fs::file_exists(image_path), 17 | glue::glue("![]({image_path}){{height='50px'}}"), 18 | "" 19 | ) 20 | ``` 21 | 22 | ### `r glue::glue("{group} {image}")` 23 | 24 | ```{r} 25 | # Include texture triangle for physical group 26 | tt_path <- "figure-output/texture-triangle.png" 27 | if (group == "Physical" & fs::file_exists(tt_path)) { 28 | texture_triangle <- glue::glue("![]({tt_path}){{width='6in'}}") 29 | } 30 | ``` 31 | 32 | ```{r} 33 | #| output: asis 34 | # Include page break after texture triangle 35 | if (group == "Physical" & fs::file_exists(tt_path)) { 36 | cat(texture_triangle) 37 | cat("\n") 38 | cat("{{< pagebreak >}}") 39 | } 40 | ``` 41 | 42 | ```{r} 43 | # Print the table 44 | table_list |> 45 | purrr::pluck(group) 46 | ``` 47 | 48 | \newline 49 | 50 | ::: {.content-visible when-format="html"} 51 | ```{r} 52 | # If HTML, convert the strip plot to interactive ggiraph 53 | if (out_type == "html") { 54 | plot_list |> 55 | purrr::pluck(group) |> 56 | convert_ggiraph( 57 | plot, 58 | plot_name = group, 59 | body_font = body_font 60 | ) 61 | } 62 | ``` 63 | ::: 64 | 65 | ::: {.content-visible unless-format="html"} 66 | ```{r} 67 | # If not HTML, just print the plot 68 | plot_list |> 69 | purrr::pluck(group) 70 | ``` 71 | ::: 72 | 73 | {{< pagebreak >}} 74 | -------------------------------------------------------------------------------- /man/convert_ggiraph.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/strip-plots.R 3 | \name{convert_ggiraph} 4 | \alias{convert_ggiraph} 5 | \title{Convert a \code{ggplot2} plot to an interactive \code{ggiraph}} 6 | \usage{ 7 | convert_ggiraph(plot, ..., body_font = "Poppins", width = 6, height = 4) 8 | } 9 | \arguments{ 10 | \item{plot}{\code{ggplot2} plot to convert to interactive \code{ggiraph}. \code{plot} must 11 | contain \verb{ggiraph::geom__interactive()}.} 12 | 13 | \item{...}{Other arguments passed to \code{\link[ggiraph:girafe_options]{ggiraph::girafe_options()}}.} 14 | 15 | \item{body_font}{Font family to use throughout plot. Defaults to 16 | \code{"Poppins"}.} 17 | 18 | \item{width}{Width of SVG output in inches. Defaults to 6.} 19 | 20 | \item{height}{Height of SVG output in inches. Defaults to 4.} 21 | } 22 | \value{ 23 | Facetted strip plots with classes of \code{girafe} and \code{htmlwidget}. 24 | } 25 | \description{ 26 | Convert a \code{ggplot2} plot to an interactive \code{ggiraph} 27 | } 28 | \examples{ 29 | # Read in wrangled example plot data 30 | df_plot_path <- soils_example("df_plot.RDS") 31 | df_plot <- readRDS(df_plot_path) 32 | 33 | # Make strip plot with all measurements and set scales based on 34 | # the category column and then apply theme. 35 | 36 | # Subset df to just biological measurement group 37 | df_plot_bio <- df_plot |> 38 | dplyr::filter(measurement_group == "biological") 39 | 40 | # NOTE: the plot gets piped into the `set_scales()` function, which gets 41 | # added to `theme_facet_strip()`. 42 | plot <- make_strip_plot( 43 | df_plot_bio, 44 | x = dummy, 45 | y = value, 46 | id = sample_id, 47 | group = abbr_unit, 48 | tooltip = label, 49 | color = category, 50 | fill = category, 51 | size = category, 52 | alpha = category, 53 | shape = category 54 | ) |> 55 | set_scales() + 56 | theme_facet_strip(body_font = "sans") 57 | 58 | # Convert static plot to interactive `ggiraph` 59 | convert_ggiraph(plot) 60 | } 61 | -------------------------------------------------------------------------------- /man/theme_facet_strip.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/strip-plots.R 3 | \name{theme_facet_strip} 4 | \alias{theme_facet_strip} 5 | \title{Theme for facetted strip plots} 6 | \usage{ 7 | theme_facet_strip( 8 | ..., 9 | body_font = "Poppins", 10 | strip_color = "#335c67", 11 | strip_text_color = "white" 12 | ) 13 | } 14 | \arguments{ 15 | \item{...}{Other arguments to pass into \code{\link[ggplot2:theme]{ggplot2::theme()}}.} 16 | 17 | \item{body_font}{Font family to use throughout plot. Defaults to \code{"Poppins"}.} 18 | 19 | \item{strip_color}{Color of facet strip background. Defaults to WaSHI blue.} 20 | 21 | \item{strip_text_color}{Color of facet strip text. Defaults to white.} 22 | } 23 | \description{ 24 | Theme for facetted strip plots 25 | } 26 | \examples{ 27 | # Read in wrangled example plot data 28 | df_plot_path <- soils_example("df_plot.RDS") 29 | df_plot <- readRDS(df_plot_path) 30 | 31 | # Subset df to just biological measurement group 32 | df_plot_bio <- df_plot |> 33 | dplyr::filter(measurement_group == "biological") 34 | 35 | # Make strip plot with all measurements and set scales based on 36 | # the category column and then apply theme. 37 | 38 | # NOTE: the plot gets piped into the `set_scales()` function, which gets 39 | # added to `theme_facet_strip()`. 40 | 41 | make_strip_plot( 42 | df_plot_bio, 43 | x = dummy, 44 | y = value, 45 | id = sample_id, 46 | group = abbr_unit, 47 | tooltip = label, 48 | color = category, 49 | fill = category, 50 | size = category, 51 | alpha = category, 52 | shape = category 53 | ) |> 54 | set_scales() + 55 | theme_facet_strip(body_font = "sans") 56 | 57 | # Example without setting theme 58 | make_strip_plot( 59 | df_plot_bio, 60 | x = dummy, 61 | y = value, 62 | id = sample_id, 63 | group = abbr_unit, 64 | tooltip = label, 65 | color = category, 66 | fill = category, 67 | size = category, 68 | alpha = category, 69 | shape = category 70 | ) |> 71 | set_scales() 72 | } 73 | -------------------------------------------------------------------------------- /inst/templates/english/03_project-summary.qmd: -------------------------------------------------------------------------------- 1 | \[EDIT: DESCRIPTION OF YOUR PROJECT\] *Thank the participating farmer. Consider 2 | including information related to how many samples you've taken, in how many 3 | crops and regions. Consider identifying members of the project team and 4 | acknowledging support from your funders and collaborators. Emphasize the 5 | objectives of the project, and include links for more information. See the 6 | example below.* 7 | 8 | ::: {.content-visible when-format="html"} 9 | ![](https://raw.githack.com/WA-Department-of-Agriculture/soils/main/figures/sampling_scene.png){height="2in" 10 | style="float:right" 11 | fig-alt="Photo of two men collecting soil samples in rangeland."} 12 | ::: 13 | 14 | Thank you for being a participant in our [State of the Soils 15 | Assessment](https://washingtonsoilhealthinitiative.com/state-of-the-soils/ "State of the Soils Assessment Webpage"). 16 | This work would not be possible without your collaboration and input. 17 | 18 | The goals of our project are to: 19 | 20 | 21 | 22 | **1)** Assess baseline soil health in Washington; 23 | 24 | **2)** Understand how climate, crop type, and management impact soil health; 25 | 26 | **3)** Develop cost-effective ways for producers to assess their own soil 27 | health, and; 28 | 29 | **4)** Develop crop- and region-specific decision support tools. 30 | 31 | To date, the Washington State Department of Agriculture (WSDA), Washington State 32 | University (WSU), conservation districts, and agricultural professionals across 33 | Washington have sampled from nearly **900** fields planted in more than **60** 34 | crop types or land uses. We are excited to share with you some preliminary 35 | results with data from your fields. 36 | 37 | 38 | 39 | ::: {.content-visible unless-format="html"} 40 | ![](https://raw.githack.com/WA-Department-of-Agriculture/soils/main/figures/sampling_scene.png){height="2in" 41 | fig-alt="Photo of two men collecting soil samples in rangeland."} 42 | ::: 43 | -------------------------------------------------------------------------------- /man/set_scales.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/strip-plots.R 3 | \name{set_scales} 4 | \alias{set_scales} 5 | \title{Define styles for producer's samples versus all samples} 6 | \usage{ 7 | set_scales( 8 | plot, 9 | primary_color = "#a60f2d", 10 | secondary_color = "#3E3D3D", 11 | other_color = "#ccc29c", 12 | language = "English" 13 | ) 14 | } 15 | \arguments{ 16 | \item{plot}{\code{ggplot} object to apply scales to.} 17 | 18 | \item{primary_color}{Color of producer's sample points. Defaults to WaSHI 19 | red} 20 | 21 | \item{secondary_color}{Color of sample points with \code{"Same crop"} or \code{"Same county"} values in the \code{category} column. Defaults to WaSHI gray.} 22 | 23 | \item{other_color}{Color of sample points with \code{"Other fields"} value in 24 | \code{category} column. Defaults to WaSHI tan.} 25 | 26 | \item{language}{Language of the legend. \code{"English"} (default) or \code{"Spanish"}.} 27 | } 28 | \value{ 29 | \code{ggplot} object with manual alpha, color, shape, and size scales 30 | applied. 31 | } 32 | \description{ 33 | Define styles for producer's samples versus all samples 34 | } 35 | \examples{ 36 | # Read in wrangled example plot data 37 | df_plot_path <- soils_example("df_plot.RDS") 38 | df_plot <- readRDS(df_plot_path) 39 | # Subset df to just biological measurement group 40 | df_plot_bio <- df_plot |> 41 | dplyr::filter(measurement_group == "biological") 42 | 43 | # Make strip plot 44 | make_strip_plot( 45 | df_plot_bio, 46 | x = dummy, 47 | y = value, 48 | id = sample_id, 49 | group = abbr_unit, 50 | tooltip = label, 51 | color = category, 52 | fill = category, 53 | size = category, 54 | alpha = category, 55 | shape = category 56 | ) |> 57 | set_scales() + 58 | theme_facet_strip(body_font = "sans") 59 | 60 | # Example without setting scales 61 | make_strip_plot( 62 | df_plot_bio, 63 | x = dummy, 64 | y = value, 65 | id = sample_id, 66 | group = abbr_unit, 67 | tooltip = label 68 | ) + 69 | theme_facet_strip(body_font = "sans") 70 | } 71 | -------------------------------------------------------------------------------- /inst/templates/spanish/03_project-summary.qmd: -------------------------------------------------------------------------------- 1 | \[EDIT: DESCRIPTION OF YOUR PROJECT\] *Thank the participating farmer. Consider 2 | including information related to how many samples you've taken, in how many 3 | crops and regions. Consider identifying members of the project team and 4 | acknowledging support from your funders and collaborators. Emphasize the 5 | objectives of the project, and include links for more information. See the 6 | example below.* 7 | 8 | ::: {.content-visible when-format="html"} 9 | ![](https://raw.githack.com/WA-Department-of-Agriculture/soils/main/figures/sampling_scene.png){height="2in" 10 | style="float:right" 11 | fig-alt="Foto de dos hombres recogiendo muestras de suelo en un pastizal."} 12 | ::: 13 | 14 | Gracias por participar en el proyecto de demostración de salud del suelo en la 15 | granja de NRCS con Viva Farms, el distrito de conservación de Skagit y la 16 | Universidad Estatal de Washington. En la primavera de 2023, tomamos muestras de 17 | suelo de sus parcelas de campo antes de que se iniciaran los tratamientos de 18 | manejo del suelo, y las analizamos para varias mediciones de laboratorio de 19 | salud del suelo para proporcionar una "línea de base" o punto de partida para 20 | rastrear el cambio a lo largo del tiempo. Estas medidas de laboratorio se 21 | complementan con evaluaciones de la salud del suelo en el campo realizadas con 22 | usted. 23 | 24 | A continuación, mostramos los resultados de las mediciones de laboratorio de sus 25 | muestras y los comparamos con otras muestras tomadas en el condado de Skagit y 26 | en todo Washington como parte de un proyecto de evaluación del [estado de los 27 | suelos](https://washingtonsoilhealthinitiative.com/state-of-the-soils/) que ha 28 | muestreado casi 1000 campos. También proporcionamos información básica sobre 29 | cómo interpretar cada una de las mediciones. 30 | 31 | 32 | 33 | ::: {.content-visible unless-format="html"} 34 | ![](https://raw.githack.com/WA-Department-of-Agriculture/soils/main/figures/sampling_scene.png){height="2in" 35 | fig-alt="Foto de dos hombres recogiendo muestras de suelo en un pastizal."} 36 | ::: 37 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: soils 2 | Title: Visualize and Report Soil Health Data 3 | Version: 1.0.1 4 | Authors@R: c( 5 | person("Jadey N", "Ryan", , "jryan@agr.wa.gov", role = c("cre", "aut"), 6 | comment = c(ORCID = "0009-0004-5998-4697") 7 | ), 8 | person("Molly", "McIlquham", role = "aut", 9 | comment = c(ORCID = "0000-0002-0152-969X") 10 | ), 11 | person("Kwabena A", "Sarpong", role = "aut"), 12 | person("Leslie M", "Michel", role = "aut"), 13 | person("Teal S", "Potter", role = "aut", 14 | comment = c(ORCID = "0000-0002-4884-2720") 15 | ), 16 | person("Deirdre", "Griffin LaHue", role = "aut", 17 | comment = c(ORCID = "0000-0001-5711-797X") 18 | ), 19 | person("Dani L", "Gelardi", role = "aut", 20 | comment = c(ORCID = "0000-0002-5015-8119") 21 | ), 22 | person("Washington State Department of Agriculture", role = c("cph", "fnd")) 23 | ) 24 | Description: Collection of soil health data visualization and reporting 25 | tools, including a RStudio project template with everything you need 26 | to generate custom HTML and Microsoft Word reports for each participant 27 | in your soil health sampling project. 28 | License: MIT + file LICENSE 29 | URL: https://github.com/WA-Department-of-Agriculture/soils, 30 | https://wa-department-of-agriculture.github.io/soils/ 31 | BugReports: https://github.com/WA-Department-of-Agriculture/soils/issues 32 | Depends: 33 | R (>= 4.1.0) 34 | Imports: 35 | cli, 36 | dplyr, 37 | flextable (>= 0.9.6), 38 | fs, 39 | ggiraph, 40 | ggplot2 (>= 3.5.0), 41 | ggrepel, 42 | ggtext, 43 | glue, 44 | htmltools, 45 | htmlwidgets, 46 | knitr, 47 | leaflet, 48 | maptiles, 49 | officer, 50 | purrr, 51 | quarto, 52 | rstudioapi, 53 | sf, 54 | tidyterra, 55 | testthat (>= 3.2.0), 56 | tidyr, 57 | utils, 58 | usethis 59 | Suggests: 60 | downloadthis, 61 | here, 62 | magick, 63 | ragg, 64 | rlang, 65 | rmarkdown 66 | VignetteBuilder: 67 | knitr 68 | Encoding: UTF-8 69 | LazyData: true 70 | Roxygen: list(markdown = TRUE) 71 | RoxygenNote: 7.3.1 72 | Config/testthat/edition: 3 73 | -------------------------------------------------------------------------------- /man/add_texture_points.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/texture-triangle.R 3 | \name{add_texture_points} 4 | \alias{add_texture_points} 5 | \title{Add points to texture triangle} 6 | \source{ 7 | Adapted from {plotrix}: 8 | \url{https://github.com/plotrix/plotrix/blob/0d4c2b065e2c2d327358ac8cdc0b0d46b89bea7f/R/soil.texture.R} 9 | } 10 | \usage{ 11 | add_texture_points( 12 | texture_df = NULL, 13 | color = "#a60f2dCC", 14 | pch = 19, 15 | size = 1.5, 16 | ... 17 | ) 18 | } 19 | \arguments{ 20 | \item{texture_df}{Data frame or matrix where each row is a soil sample and 21 | three numeric columns contain sand, silt, and clay percentages or 22 | proportions. The order of sand, silt, clay is required for correct 23 | plotting.} 24 | 25 | \item{color}{Color of the points. Defaults to WaSHI red.} 26 | 27 | \item{pch}{Numeric value of plotting symbol. See \code{\link[graphics:points]{graphics::points()}} for 28 | options and details. Defaults to 19, which is a filled-in circle.} 29 | 30 | \item{size}{Numeric expansion factor for points. Defaults to 1.5.} 31 | 32 | \item{...}{Other arguments passed to \code{\link[graphics:points]{graphics::points()}}.} 33 | } 34 | \value{ 35 | A list of x, y coordinates of the soil textures plotted. 36 | } 37 | \description{ 38 | To vary color, symbol, and size of points by a grouping variable, call this 39 | function once for each value of the grouping variable. Add layers from bottom 40 | to top. The below example adds the red points last so they are plotted on top 41 | of the gray points. 42 | } 43 | \examples{ 44 | texture <- soils::washi_data |> 45 | dplyr::select( 46 | sand = sand_percent, 47 | silt = silt_percent, 48 | clay = clay_percent 49 | ) 50 | 51 | make_texture_triangle(body_font = "sans") 52 | 53 | # Add gray points 54 | add_texture_points( 55 | tail(texture, 5), 56 | color = "#3E3D3D90", 57 | pch = 19 58 | ) 59 | 60 | # Add red points 61 | add_texture_points( 62 | head(texture, 5), 63 | color = "#a60f2dCC", 64 | pch = 15 65 | ) 66 | 67 | # Note the text appears squished in this example since the width, height, 68 | # and resolution have been optimized to print the figure 6 in wide in the 69 | # report. 70 | } 71 | -------------------------------------------------------------------------------- /inst/templates/spanish/02_section-template.qmd: -------------------------------------------------------------------------------- 1 | ```{r} 2 | # If the report fails to render at the `create-measurement-group-sections` chunk 3 | # in `01_producer-report.qmd`, run all chunks above to load the data in your 4 | # environment. Then uncomment this group assignment and run each code chunk in 5 | # this file interactively to troubleshoot. 6 | 7 | # group <- "Mediciones físicas" 8 | ``` 9 | 10 | ```{r} 11 | # Get image name from Spanish translation 12 | image_name <- dplyr::case_when( 13 | grepl("físico|físicas", group, ignore.case = TRUE) ~ "physical", 14 | grepl("biológico|biológicas", group, ignore.case = TRUE) ~ "biological", 15 | grepl("químico|químicas", group, ignore.case = TRUE) ~ "chemical" 16 | ) 17 | 18 | # Get path of measurement group image 19 | image_path <- glue::glue("images/{image_name}.png") 20 | 21 | # Insert image into header if image exists for that measurement group 22 | image <- ifelse( 23 | fs::file_exists(image_path), 24 | glue::glue("![]({image_path}){{height='50px'}}"), 25 | "" 26 | ) 27 | ``` 28 | 29 | ### `r glue::glue("{group} {image}")` 30 | 31 | ```{r} 32 | # Include texture triangle for physical group 33 | tt_path <- "figure-output/texture-triangle.png" 34 | if (group == "Mediciones físicas" & fs::file_exists(tt_path)) { 35 | texture_triangle <- glue::glue("![]({tt_path}){{width='6in'}}") 36 | } 37 | ``` 38 | 39 | ```{r} 40 | #| output: asis 41 | # Include page break after texture triangle 42 | if (group == "Mediciones físicas" & fs::file_exists(tt_path)) { 43 | cat(texture_triangle) 44 | cat("\n") 45 | cat("{{< pagebreak >}}") 46 | } 47 | ``` 48 | 49 | ```{r} 50 | # Print the table 51 | table_list |> 52 | purrr::pluck(group) 53 | ``` 54 | 55 | \newline 56 | 57 | ::: {.content-visible when-format="html"} 58 | ```{r} 59 | # If HTML, convert the strip plot to interactive ggiraph 60 | if (out_type == "html") { 61 | plot_list |> 62 | purrr::pluck(group) |> 63 | convert_ggiraph( 64 | plot, 65 | plot_name = group, 66 | body_font = body_font 67 | ) 68 | } 69 | ``` 70 | ::: 71 | 72 | ::: {.content-visible unless-format="html"} 73 | ```{r} 74 | # If not HTML, just print the plot 75 | plot_list |> 76 | purrr::pluck(group) 77 | ``` 78 | ::: 79 | 80 | {{< pagebreak >}} 81 | -------------------------------------------------------------------------------- /vignettes/render-example.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Render the example reports" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Render the example reports} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | ```{r, include = FALSE} 11 | knitr::opts_chunk$set( 12 | collapse = TRUE, 13 | comment = "#>" 14 | ) 15 | ``` 16 | 17 | **Before modifying anything** (data, report content, or style), render the 18 | example report with the anonymized built-in data to ensure your system is set up 19 | correctly. 20 | 21 | Open `01_producer-report.qmd`. Click the `Render` button to generate an HTML 22 | report or the `down arrow` (▼) to open a drop down menu to choose between HTML 23 | or MS Word. Try rendering the example report in both formats. 24 | 25 | If rendering to HTML, you can check the `Render on Save` option to automatically 26 | update the preview whenever you save the document. 27 | 28 | ![](../man/figures/render.png){width="80%" 29 | fig-alt="RStudio Quarto Render button with a dropdown for HTML and MS Word. Render on Save option is checked."} 30 | 31 | If the rendered report doesn't immediately open, you can find it in your project 32 | directory with the same name as the main Quarto `.qmd` file 33 | (`01_producer-report.qmd`). Newly rendered files can usually be found at the 34 | bottom of the files pane. 35 | 36 | ![](../man/figures/rendered_report_location.png){width="50%" 37 | fig-alt="RStudio screenshot of files pane with boxes around the project directory path, the template 01_producer-report.qmd file, and the rendered report 01_producer-report.html"} 38 | 39 | It should take no more than one minute to render a single example report. 40 | 41 |
42 | 43 | Demo videos 44 | 45 | **HTML** 46 | 47 | 50 | 51 | **MS Word** 52 | 53 | 56 | 57 |
58 | 59 | **See the [rendered example 60 | reports](https://wa-department-of-agriculture.github.io/soils/articles/examples.html).** 61 | -------------------------------------------------------------------------------- /inst/templates/english/R/render-reports.R: -------------------------------------------------------------------------------- 1 | # Use this script to render all reports at once ################################ 2 | 3 | # After editing the dataset and optionally the location to move the 4 | # rendered reports, click the `Source` button in RStudio. 5 | 6 | # Read in data ================================================================= 7 | 8 | # EDIT: Replace `washi-data.csv` with the name of the same dataset used in 9 | # 01_producer-report.qmd. 10 | data <- read.csv( 11 | here::here("data/washi-data.csv"), 12 | check.names = FALSE, 13 | encoding = "UTF-8" 14 | ) 15 | 16 | # Create a df with inputs for quarto::quarto_render() ========================== 17 | 18 | # This creates a new df called `reports_html` with a row for every unique year 19 | # and producer combo for the entire dataset. 20 | # 21 | # If you want a subset, filter the dataframe to include only the producers you 22 | # want to create a report for. 23 | 24 | ## HTML reports 25 | reports_html <- data |> 26 | dplyr::distinct(year, producer_id) |> 27 | dplyr::mutate( 28 | output_file = glue::glue("{year}_{producer_id}_Report.html"), 29 | output_format = "html", 30 | execute_params = purrr::map2( 31 | year, 32 | producer_id, 33 | \(year, producer_id) list(year = year, producer_id = producer_id) 34 | ) 35 | ) |> 36 | dplyr::select(output_file, output_format, execute_params) 37 | 38 | ## Word docs 39 | reports_docx <- reports_html |> 40 | dplyr::mutate( 41 | output_file = gsub("html", "docx", output_file), 42 | output_format = "docx" 43 | ) 44 | 45 | ## Bind HTML and docx report dfs together 46 | reports <- dplyr::bind_rows(reports_html, reports_docx) 47 | 48 | # Render all reports to the project directory ================================== 49 | reports |> 50 | purrr::pwalk( 51 | quarto::quarto_render, 52 | input = "01_producer-report.qmd", 53 | .progress = TRUE 54 | ) 55 | 56 | # Move rendered reports to a different directory =============================== 57 | 58 | # Create directory called "reports" 59 | output_dir <- fs::dir_create(here::here("reports")) 60 | 61 | # List files with extensions html or docx. 62 | files <- fs::dir_ls(here::here(), regexp = ".html$|.docx$") 63 | 64 | # Move the files 65 | fs::file_move( 66 | path = files, 67 | new_path = output_dir 68 | ) 69 | -------------------------------------------------------------------------------- /inst/templates/spanish/R/render-reports.R: -------------------------------------------------------------------------------- 1 | # Use this script to render all reports at once ################################ 2 | 3 | # After editing the dataset and optionally the location to move the 4 | # rendered reports, click the `Source` button in RStudio. 5 | 6 | # Read in data ================================================================= 7 | 8 | # EDIT: Replace `washi-data.csv` with the name of the same dataset used in 9 | # 01_producer-report.qmd. 10 | data <- read.csv( 11 | here::here("data/washi-data.csv"), 12 | check.names = FALSE, 13 | encoding = "UTF-8" 14 | ) 15 | 16 | # Create a df with inputs for quarto::quarto_render() ========================== 17 | 18 | # This creates a new df called `reports_html` with a row for every unique year 19 | # and producer combo for the entire dataset. 20 | # 21 | # If you want a subset, filter the dataframe to include only the producers you 22 | # want to create a report for. 23 | 24 | ## HTML reports 25 | reports_html <- data |> 26 | dplyr::distinct(year, producer_id) |> 27 | dplyr::mutate( 28 | output_file = glue::glue("{year}_{producer_id}_Report.html"), 29 | output_format = "html", 30 | execute_params = purrr::map2( 31 | year, 32 | producer_id, 33 | \(year, producer_id) list(year = year, producer_id = producer_id) 34 | ) 35 | ) |> 36 | dplyr::select(output_file, output_format, execute_params) 37 | 38 | ## Word docs 39 | reports_docx <- reports_html |> 40 | dplyr::mutate( 41 | output_file = gsub("html", "docx", output_file), 42 | output_format = "docx" 43 | ) 44 | 45 | ## Bind HTML and docx report dfs together 46 | reports <- dplyr::bind_rows(reports_html, reports_docx) 47 | 48 | # Render all reports to the project directory ================================== 49 | reports |> 50 | purrr::pwalk( 51 | quarto::quarto_render, 52 | input = "01_producer-report.qmd", 53 | .progress = TRUE 54 | ) 55 | 56 | # Move rendered reports to a different directory =============================== 57 | 58 | # Create directory called "reports" 59 | output_dir <- fs::dir_create(here::here("reports")) 60 | 61 | # List files with extensions html or docx. 62 | files <- fs::dir_ls(here::here(), regexp = ".html$|.docx$") 63 | 64 | # Move the files 65 | fs::file_move( 66 | path = files, 67 | new_path = output_dir 68 | ) 69 | -------------------------------------------------------------------------------- /inst/templates/english/resources/styles.css: -------------------------------------------------------------------------------- 1 | /* Edit these :root variables */ 2 | :root { 3 | --primary-color: #023B2C; 4 | --secondary-color: #335c67; 5 | --link-color: #a60f2d; 6 | --light-color: #F2F0E6; 7 | --fg-color: white; /* color for text with colored background*/ 8 | --heading-font: "Georgia"; 9 | --body-font: "Arial"; 10 | } 11 | 12 | /* You don't need to edit the below content unless you want to 13 | further customize your HTML report style */ 14 | 15 | p.subtitle { 16 | margin-top: 0.95em; 17 | margin-bottom: -0.05em; 18 | } 19 | 20 | .lead { 21 | font-family: var(--heading-font); 22 | font-size: 1.5rem; 23 | font-weight: bold; 24 | color: var(--secondary-color); 25 | text-align: right; 26 | } 27 | 28 | p { 29 | font-family: var(--body-font); 30 | } 31 | 32 | .tab-pane>p { 33 | padding-top: 0em; 34 | } 35 | 36 | a { 37 | font-family: var(--body-font); 38 | color: var(--link-color); 39 | } 40 | 41 | a:hover { 42 | color: var(--link-color); 43 | filter: brightness(100%); 44 | } 45 | 46 | .sidebar nav[role=doc-toc] ul>li>a.active { 47 | border-left: 1px solid var(--link-color); 48 | color: var(--link-color)!important; 49 | } 50 | 51 | .sidebar nav[role=doc-toc] ul>li>ul>li>a.active { 52 | border-left: 1px solid var(--link-color); 53 | color: var(--link-color)!important; 54 | } 55 | 56 | h1, h2, h3, h4, h5 { 57 | font-family: var(--heading-font); 58 | color: var(--primary-color); 59 | font-weight: bold; 60 | } 61 | 62 | .sidebar nav[role=doc-toc]>h2 { 63 | font-family: var(--heading-font); 64 | font-weight: bold; 65 | font-size: 1em; 66 | } 67 | 68 | .nav-tabs .nav-link { 69 | font-family: var(--heading-font); 70 | } 71 | 72 | caption, .table-caption { 73 | text-align: left!; 74 | } 75 | 76 | div.callout-tip.callout { 77 | background: var(--light-color); 78 | } 79 | 80 | div.callout-tip.callout { 81 | font-family: var(--body-font); 82 | border-left-color: var(--primary-color); 83 | } 84 | 85 | div.callout-tip.callout-style-default>.callout-header { 86 | background-color: var(--primary-color); 87 | color: var(--fg-color); 88 | } 89 | 90 | .btn-success { 91 | margin-top: 1em; 92 | color: var(--fg-color); 93 | background-color: var(--primary-color); 94 | border-color: var(--primary-color); 95 | } 96 | 97 | .ggiraph-svg { 98 | height: auto !important; 99 | } 100 | -------------------------------------------------------------------------------- /inst/templates/spanish/resources/styles.css: -------------------------------------------------------------------------------- 1 | /* Edit these :root variables */ 2 | :root { 3 | --primary-color: #023B2C; 4 | --secondary-color: #335c67; 5 | --link-color: #a60f2d; 6 | --light-color: #F2F0E6; 7 | --fg-color: white; /* color for text with colored background*/ 8 | --heading-font: "Georgia"; 9 | --body-font: "Arial"; 10 | } 11 | 12 | /* You don't need to edit the below content unless you want to 13 | further customize your HTML report style */ 14 | 15 | p.subtitle { 16 | margin-top: 0.95em; 17 | margin-bottom: -0.05em; 18 | } 19 | 20 | .lead { 21 | font-family: var(--heading-font); 22 | font-size: 1.5rem; 23 | font-weight: bold; 24 | color: var(--secondary-color); 25 | text-align: right; 26 | } 27 | 28 | p { 29 | font-family: var(--body-font); 30 | } 31 | 32 | .tab-pane>p { 33 | padding-top: 0em; 34 | } 35 | 36 | a { 37 | font-family: var(--body-font); 38 | color: var(--link-color); 39 | } 40 | 41 | a:hover { 42 | color: var(--link-color); 43 | filter: brightness(100%); 44 | } 45 | 46 | .sidebar nav[role=doc-toc] ul>li>a.active { 47 | border-left: 1px solid var(--link-color); 48 | color: var(--link-color)!important; 49 | } 50 | 51 | .sidebar nav[role=doc-toc] ul>li>ul>li>a.active { 52 | border-left: 1px solid var(--link-color); 53 | color: var(--link-color)!important; 54 | } 55 | 56 | h1, h2, h3, h4, h5 { 57 | font-family: var(--heading-font); 58 | color: var(--primary-color); 59 | font-weight: bold; 60 | } 61 | 62 | .sidebar nav[role=doc-toc]>h2 { 63 | font-family: var(--heading-font); 64 | font-weight: bold; 65 | font-size: 1em; 66 | } 67 | 68 | .nav-tabs .nav-link { 69 | font-family: var(--heading-font); 70 | } 71 | 72 | caption, .table-caption { 73 | text-align: left!; 74 | } 75 | 76 | div.callout-tip.callout { 77 | background: var(--light-color); 78 | } 79 | 80 | div.callout-tip.callout { 81 | font-family: var(--body-font); 82 | border-left-color: var(--primary-color); 83 | } 84 | 85 | div.callout-tip.callout-style-default>.callout-header { 86 | background-color: var(--primary-color); 87 | color: var(--fg-color); 88 | } 89 | 90 | .btn-success { 91 | margin-top: 1em; 92 | color: var(--fg-color); 93 | background-color: var(--primary-color); 94 | border-color: var(--primary-color); 95 | } 96 | 97 | .ggiraph-svg { 98 | height: auto !important; 99 | } 100 | -------------------------------------------------------------------------------- /vignettes/examples.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Example reports" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Example reports} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | ```{r, include = FALSE} 11 | knitr::opts_chunk$set( 12 | collapse = TRUE, 13 | comment = "#>" 14 | ) 15 | ``` 16 | 17 | # HTML 18 | 19 | HTML reports contain interactive features such as a table of contents, map, 20 | figures, and a downloadable spreadsheet. These reports are "self-contained" and 21 | embed all dependencies in the HTML file. As a result, the file size can be quite 22 | large. 23 | 24 | These reports can be distributed with cloud storage (Google Drive, Box.com, 25 | Dropbox.com, etc.). Report recipients must download the `.html` file to their 26 | computer and then open the file in their web browser. 27 | 28 | ## English 29 | 30 | Open this report in a [new 31 | tab](https://soils-example-html.netlify.app/){target="_blank"}. 32 | 33 | ```{r echo=FALSE, out.width="100%"} 34 | knitr::include_url( 35 | "https://soils-example-html.netlify.app/", height = "500px") 36 | ``` 37 | 38 | ## Spanish 39 | 40 | Open this report in a [new 41 | tab](https://soils-spanish-example.netlify.app/){target="_blank"}. 42 | 43 | ```{r echo=FALSE, out.width="100%"} 44 | knitr::include_url( 45 | "https://soils-spanish-example.netlify.app/", height = "500px") 46 | ``` 47 | 48 | # MS Word 49 | 50 | This example report was rendered to a `.docx` file and then converted to a PDF 51 | for web publishing. 52 | 53 | ## English 54 | 55 | Open this report in a [new 56 | tab](https://drive.google.com/file/d/1VsRDa4zzzevCVYK17RvtbxHVu2nELCUc/preview){target="_blank"}. 57 | 58 | 59 | 60 |

Oops! Your browser doesn't seem to support embedded PDFs.

61 | 62 |

Try 63 | downloading it instead.

64 | 65 |
66 | 67 | ## Spanish 68 | 69 | Open this report in a [new 70 | tab](https://drive.google.com/file/d/1WkyJgPX4m4s4yaPvwa6JTOIcKW-VBGFO/preview){target="_blank"}. 71 | 72 | 73 | 74 |

Oops! Your browser doesn't seem to support embedded PDFs.

75 | 76 |

Try 77 | downloading it instead.

78 | -------------------------------------------------------------------------------- /man/add_legend.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/texture-triangle.R 3 | \name{add_legend} 4 | \alias{add_legend} 5 | \title{Add a legend to the texture triangle} 6 | \usage{ 7 | add_legend( 8 | x = 1, 9 | y = 0.7, 10 | box = FALSE, 11 | legend = c("Your fields", "Same county", "Same crop", "Other fields"), 12 | color = c("#a60f2dCC", "#3E3D3D99", "#3E3D3D99", "#ccc29c80"), 13 | pch = c(15, 17, 18, 19), 14 | size = c(2.4, 2.16, 2.16, 1.36), 15 | vertical_spacing = 1.5, 16 | ... 17 | ) 18 | } 19 | \arguments{ 20 | \item{x, y}{X and Y coordinates used to position the legend. Location may also 21 | be specified by setting \code{x} to a single keyword from the list 22 | \code{"bottomright"}, \code{"bottom"}, \code{"bottomleft"}, \code{"left"}, \code{"topleft"}, 23 | \code{"top"}, \code{"topright"}, \code{"right"}, and \code{"center"}.} 24 | 25 | \item{box}{Boolean. \code{TRUE} to draw a box around the legend. Defaults to \code{FALSE} 26 | for no box.} 27 | 28 | \item{legend}{Character vector to appear in legend.} 29 | 30 | \item{color}{Character vector of the color of the points.} 31 | 32 | \item{pch}{Numeric vector of plotting symbols. See \code{\link[graphics:points]{graphics::points()}} for 33 | options and details.} 34 | 35 | \item{size}{Numeric expansion factor for points.} 36 | 37 | \item{vertical_spacing}{Numeric spacing factor for vertical line distances 38 | between each legend item.} 39 | 40 | \item{...}{Other arguments passed to \code{\link[graphics:legend]{graphics::legend()}}.} 41 | } 42 | \value{ 43 | A list with list components for the legend's box and legend's 44 | text(s). 45 | } 46 | \description{ 47 | Add a legend to the texture triangle 48 | } 49 | \examples{ 50 | texture <- washi_data |> 51 | dplyr::select( 52 | sand = sand_percent, 53 | silt = silt_percent, 54 | clay = clay_percent 55 | ) 56 | 57 | make_texture_triangle(body_font = "sans") 58 | 59 | # Add gray points 60 | add_texture_points( 61 | tail(texture, 5), 62 | color = "#3E3D3D90", 63 | pch = 19 64 | ) 65 | 66 | # Add red points 67 | add_texture_points( 68 | head(texture, 5), 69 | color = "#a60f2dCC", 70 | pch = 15 71 | ) 72 | 73 | # Add legend 74 | add_legend( 75 | legend = c("Red squares", "Gray circles"), 76 | color = c("#a60f2dCC", "#3E3D3D90"), 77 | pch = c(15, 19), 78 | vertical_spacing = 2 79 | ) 80 | 81 | # Note the text appears squished in this example since the width, height, 82 | # and resolution have been optimized to print the figure 6 in wide in the 83 | # report. 84 | } 85 | -------------------------------------------------------------------------------- /man/make_strip_plot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/strip-plots.R 3 | \name{make_strip_plot} 4 | \alias{make_strip_plot} 5 | \title{Make a facetted strip plot} 6 | \usage{ 7 | make_strip_plot( 8 | df, 9 | ..., 10 | x = dummy, 11 | y = value, 12 | id = sample_id, 13 | group = abbr_unit, 14 | tooltip = label, 15 | language = "English" 16 | ) 17 | } 18 | \arguments{ 19 | \item{df}{Data frame to plot.} 20 | 21 | \item{...}{Other arguments passed to \code{\link[graphics:points]{graphics::points()}}.} 22 | 23 | \item{x}{Column for x-axis. For these strip plots, we recommend using a dummy 24 | variable to act as a placeholder. Defaults to a column named \code{dummy} with 25 | only one value ("dummy") for all rows.} 26 | 27 | \item{y}{Column for y-axis. Defaults to \code{value}.} 28 | 29 | \item{id}{Column with unique identifiers for each sample to use as \code{data_id} 30 | for interactive plots. Defaults to \code{sample_id}.} 31 | 32 | \item{group}{Column to facet by. Defaults to \code{abbr_unit}.} 33 | 34 | \item{tooltip}{Column with tooltip labels for interactive plots.} 35 | 36 | \item{language}{Language of the legend. \code{"English"} (default) or \code{"Spanish"}.} 37 | } 38 | \value{ 39 | Facetted \code{ggplot2} strip plots. 40 | } 41 | \description{ 42 | Make a facetted strip plot 43 | } 44 | \examples{ 45 | # Read in wrangled example plot data 46 | df_plot_path <- soils_example("df_plot.RDS") 47 | df_plot <- readRDS(df_plot_path) 48 | 49 | # Subset df to just biological measurement group 50 | df_plot_bio <- df_plot |> 51 | dplyr::filter(measurement_group == "biological") 52 | 53 | # Make strip plot with all measurements and set scales based on 54 | # the category column and then apply theme. 55 | 56 | # NOTE: the plot gets piped into the `set_scales()` function, which gets 57 | # added to `theme_facet_strip()`. 58 | 59 | make_strip_plot( 60 | df_plot_bio, 61 | x = dummy, 62 | y = value, 63 | id = sample_id, 64 | group = abbr_unit, 65 | tooltip = label, 66 | color = category, 67 | fill = category, 68 | size = category, 69 | alpha = category, 70 | shape = category 71 | ) |> 72 | set_scales() + 73 | theme_facet_strip(body_font = "sans") 74 | 75 | # Example of strip plot without scales or theme functions 76 | make_strip_plot(df_plot_bio) 77 | 78 | # Example of strip plot with `x` set to the facet group instead of a dummy 79 | # variable. The dummy variable is what centers the points within the subplot. 80 | make_strip_plot( 81 | df_plot_bio, 82 | x = abbr_unit, 83 | y = value, 84 | id = sample_id, 85 | group = abbr_unit, 86 | tooltip = label, 87 | color = category, 88 | fill = category, 89 | size = category, 90 | alpha = category, 91 | shape = category 92 | ) |> 93 | set_scales() + 94 | theme_facet_strip(body_font = "sans") 95 | } 96 | -------------------------------------------------------------------------------- /pkgdown/_pkgdown.yml: -------------------------------------------------------------------------------- 1 | url: https://wa-department-of-agriculture.github.io/soils/ 2 | development: 3 | mode: auto 4 | 5 | template: 6 | bootstrap: 5 7 | theme: a11y-light 8 | bslib: 9 | bg: '#faf9f6' 10 | fg: black 11 | primary: '#023b2c' 12 | light: '#023b2c' 13 | success: '#335c67' 14 | heading_font: 15 | google: Lato 16 | base_font: 17 | google: Poppins 18 | 19 | navbar: 20 | type: dark 21 | structure: 22 | left: [home, primers, tutorials, examples, functions] 23 | right: [search, github] 24 | components: 25 | home: 26 | icon: fa-home 27 | href: index.html 28 | aria-label: Home 29 | primers: 30 | text: Primers 31 | menu: 32 | - text: "Quarto" 33 | href: articles/quarto.html 34 | - text: "Markdown" 35 | href: articles/markdown.html 36 | tutorials: 37 | text: Tutorials 38 | menu: 39 | - text: "Create a {soils} project" 40 | href: articles/project.html 41 | - text: "Render the example reports" 42 | href: articles/render-example.html 43 | - text: "Import your data" 44 | href: articles/data.html 45 | - text: "Customize & write" 46 | href: articles/customize.html 47 | - text: "Render your reports" 48 | href: articles/render.html 49 | - text: ------- 50 | - text: "Troubleshoot" 51 | href: articles/troubleshoot.html 52 | examples: 53 | text: "Examples" 54 | href: articles/examples.html 55 | functions: 56 | text: Functions 57 | href: reference/index.html 58 | 59 | articles: 60 | - title: Primers 61 | desc: ~ 62 | contents: 63 | - '`quarto`' 64 | - '`markdown`' 65 | - title: Tutorials 66 | desc: ~ 67 | contents: 68 | - '`project`' 69 | - '`render-example`' 70 | - '`data`' 71 | - '`customize`' 72 | - '`render`' 73 | - '`troubleshoot`' 74 | - title: Example Reports 75 | desc: ~ 76 | contents: 77 | - '`examples`' 78 | 79 | news: 80 | one-page: true 81 | 82 | reference: 83 | - title: Create a {soils} project 84 | contents: create_soils 85 | - title: Data wrangling 86 | contents: 87 | - get_n_texture_by_var 88 | - summarize_by_project 89 | - summarize_by_var 90 | - get_table_headers 91 | - prep_for_map 92 | - title: Map 93 | contents: make_leaflet 94 | - title: Plots 95 | contents: 96 | - make_texture_triangle 97 | - add_texture_points 98 | - add_legend 99 | - make_strip_plot 100 | - theme_facet_strip 101 | - set_scales 102 | - convert_ggiraph 103 | - title: Tables 104 | contents: 105 | - make_ft 106 | - unit_hline 107 | - format_ft_colors 108 | - style_ft 109 | - title: Helpers 110 | contents: 111 | - calculate_mode 112 | - pull_unique 113 | - title: Example data 114 | contents: 115 | - soils_example 116 | - washi_data 117 | - data_dictionary 118 | -------------------------------------------------------------------------------- /R/create-soils.R: -------------------------------------------------------------------------------- 1 | #' Create a project directory for generating soil health reports 2 | #' 3 | #' Creates an RStudio project containing Quarto template and resources (images, 4 | #' style sheets, render.R script). 5 | #' 6 | #' @param path Name of project directory to be created. 7 | #' @param template Template type. Either "English" or "Spanish". 8 | #' @param overwrite Boolean. Overwrite the existing project? 9 | #' @param open Boolean. Open the newly created project? 10 | #' 11 | #' @source Adapted from `golem::create_golem()`. 12 | #' 13 | #' @return A new project directory containing template and resources. 14 | #' @export 15 | #' 16 | #' @examples 17 | #' \dontrun{ 18 | #' # Create temporary directory 19 | #' dir <- tempdir() 20 | #' 21 | #' # Create soils project 22 | #' create_soils(dir, overwrite = TRUE) 23 | #' 24 | #' # Delete temporary directory 25 | #' unlink(dir, recursive = TRUE) 26 | #' } 27 | create_soils <- function( 28 | path, 29 | template = "English", 30 | overwrite = FALSE, 31 | open = TRUE 32 | ) { 33 | if (missing(path)) { 34 | cli::cli_abort(c( 35 | "!" = "{.arg path} must be provided.", 36 | "i" = "Where do you want to create this project?", 37 | "i" = "For example, {.code create_soils(path = 'path/to/my/directory')}." 38 | )) 39 | } 40 | 41 | # template arg must be "english" or "spanish" 42 | rlang::arg_match( 43 | arg = template, 44 | values = c("English", "Spanish") 45 | ) 46 | 47 | path <- fs::path_norm(path) 48 | 49 | dir_exists <- fs::dir_exists(path) 50 | overwriting <- isTRUE(overwrite) 51 | 52 | if (dir_exists && !overwriting) { 53 | cli::cli_abort( 54 | c( 55 | "!" = "{.path {path}} already exists.", 56 | "i" = "To overwrite, use: \\ 57 | {.code create_soils({.str {path}}, overwrite = TRUE)}" 58 | ) 59 | ) 60 | } 61 | 62 | if (dir_exists && overwriting) { 63 | cat_red_bullet("Overwriting existing project.") 64 | if (rstudioapi::isAvailable() & isTRUE(open)) { 65 | rstudioapi::openProject(path, newSession = TRUE) 66 | } 67 | } 68 | 69 | if (!dir_exists) { 70 | cli::cat_rule("Creating directory") 71 | usethis::create_project( 72 | path = path, 73 | open = open 74 | ) 75 | } 76 | 77 | cat_green_tick("Created project directory") 78 | 79 | invisible({ 80 | template <- soils_sys(paste0("templates/", tolower(template))) 81 | 82 | # Copy over whole directory 83 | fs::dir_copy( 84 | path = template, 85 | new_path = path, 86 | overwrite = TRUE 87 | ) 88 | }) 89 | } 90 | 91 | #' Create a project directory for soil health reports using a Quarto template 92 | #' 93 | #' For use only in RStudio "New Project" GUI. Defaults to not overwrite and not 94 | #' open the project. 95 | #' @inheritParams create_soils 96 | #' @noRd 97 | create_soils_gui <- function(path, ...) { 98 | dots <- list(...) 99 | 100 | create_soils( 101 | path = path, 102 | template = dots$template, 103 | overwrite = FALSE, 104 | open = FALSE 105 | ) 106 | } 107 | -------------------------------------------------------------------------------- /vignettes/render.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Render your reports" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Render your reports} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | ```{r, include = FALSE} 11 | knitr::opts_chunk$set( 12 | collapse = TRUE, 13 | comment = "#>" 14 | ) 15 | ``` 16 | 17 | Render a single report at a time with the RStudio user interface, or 18 | programmatically render all reports (for all producers and in all formats) with 19 | the `render_reports.R` script. 20 | 21 | ## Using RStudio 22 | 23 | To generate and preview the report with the default parameters[^1], use the 24 | `Render` button or keyboard shortcut (`Ctrl + Shift + K`). Use this workflow to 25 | quickly iterate on content and style. For HTML reports, check the 26 | `Render on Save` option to automatically update the preview whenever you save 27 | the document. 28 | 29 | [^1]: The default parameters are the `producer_id` and `year` combination that 30 | was set in the YAML header of `01_producer-report.qmd.` 31 | 32 | ![](../man/figures/render.png){width="80%" 33 | fig-alt="RStudio Quarto Render button with a dropdown for HTML and MS Word. Render on Save option is checked."} 34 | 35 | The [**Render the example 36 | reports**](https://wa-department-of-agriculture.github.io/soils/articles/render-example.html) 37 | tutorial provides additional details on rendering reports with the RStudio user 38 | interface. 39 | 40 | ## Using `render_reports.R` 41 | 42 | `render-reports.R` creates a dataframe and then uses `purrr::pwalk()` to iterate 43 | over each row, rendering all reports in both HTML and MS Word formats. After 44 | rendering, all reports are moved to a folder called `reports` in the project 45 | directory. 46 | 47 | 1. Edit `render_reports.R` to read in the same dataset in the `load-data` chunk 48 | of `01_producer-report.qmd`. For example, if your dataset is called 49 | `my-data.csv`, replace `washi-data.csv` with `my-data.csv` in Line 11. 50 | 51 | 2. Click `Source` to run this script and generate all reports in all formats at 52 | once. 53 | 54 | ![](../man/figures/render-reports.png){fig-alt="RStudio screenshot of `render-reports.R` script with box and arrow instructing the user to replace `washi-data.csv` with the name of the user's data file. A second box and arrow instructs the user to click the Source button to run the script and generate all reports."} 55 | 56 | **Optionally**, to render reports for only a subset of producers, filter the 57 | dataframe to include only this subset. The last line of the below code block 58 | demonstrates how to filter the data to three specific producers. 59 | 60 | ```{r} 61 | #| eval: false 62 | 63 | # EDIT: Replace `washi-data.csv` with the name of the same dataset used in 64 | # 01_producer-report.qmd. 65 | data <- read.csv( 66 | here::here("data/washi-data.csv"), 67 | check.names = FALSE, 68 | encoding = "UTF-8" 69 | ) |> 70 | dplyr::filter(producer_id %in% c("WUY05", "RHM05", "ENR07")) 71 | ``` 72 | 73 | ## Video demo of `render-reports.R` 74 | 75 | 78 | 79 | -------------------------------------------------------------------------------- /vignettes/project.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Create a {soils} project" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Create a {soils} project} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | ```{r, include = FALSE} 11 | knitr::opts_chunk$set( 12 | collapse = TRUE, 13 | comment = "#>" 14 | ) 15 | ``` 16 | 17 | There are two ways to create a {soils} project. The below examples create a 18 | project titled "soils-demo". Replace this name with what you'd like the project 19 | and directory to be named. 20 | 21 | ## Option 1. RStudio project wizard 22 | 23 | The RStudio user interface is the easiest and recommended way to create a new 24 | {soils} project. 25 | 26 | `Open RStudio` \> `File` \> `New Project` \> `New Directory` \> 27 | **`Quarto Soil Health Report`** 28 | 29 | ![](../man/figures/project_wizard-1.png){width="70%" 30 | fig-alt="Screenshot of RStudio New Project Wizard with Quarto Soil Health Report selected."} 31 | 32 | Enter your desired directory name, browse to where you want the project to live, 33 | choose which template to use (currently the options are *English* or *Spanish*), 34 | and check whether you want the project to open in a new RStudio session. 35 | 36 | ![](../man/figures/project_wizard-2.png){width="70%" 37 | fig-alt="Screenshot of RStudio New Project Wizard for Quarto Soil Health Report. Enter directory name, path, choose which template type to use, and check whether you want the project to open in a new RStudio session."} 38 | 39 | The new RStudio project will open with the template Quarto report 40 | (`01_producer-report.qmd`) and the R script (`render-reports.R`) to render all 41 | reports at once. The rest of the project files will appear in the files pane. 42 | 43 | ![](../man/figures/new_project.png){fig-alt="Screenshot of new RStudio project called demo-soils. A Quarto file called 01_producer-report.qmd is open and there is a tab for an R script called render_reports.R that renders all reports at once. The files pane is open with a project directory full of other Quarto files, styling resources, example images and data."} 44 | 45 |
46 | 47 | Demo video 48 | 49 | 52 | 53 |
54 | 55 | ## Option 2. RStudio console 56 | 57 | Run the below code in your console to create a {soils} project called 58 | "soils-demo" in your default working directory. 59 | 60 | ```{r, eval=FALSE} 61 | soils::create_soils(path = "soils-demo") 62 | ``` 63 | 64 | The following will print in your console. Note the location of your new project. 65 | 66 | ![](../man/figures/create_soils.png){fig-alt="Output from running soils::create_soils(path = 'soils-demo') in the RStudio console"} 67 | 68 | ## Project structure 69 | 70 | Both options will create and launch a new RStudio project with the below files. 71 | 72 |
73 | 74 | Project directory and files 75 | 76 | ``` 77 | ├── 01_producer-report.qmd 78 | ├── 02_section-template.qmd 79 | ├── 03_project-summary.qmd 80 | ├── 04_soil-health-background.qmd 81 | ├── 05_physical-measurements.qmd 82 | ├── 06_biological-measurements.qmd 83 | ├── 07_chemical-measurements.qmd 84 | ├── 08_looking-forward.qmd 85 | ├── 09_acknowledgement.qmd 86 | ├── data 87 | │ ├── data-dictionary.csv 88 | │ └── washi-data.csv 89 | ├── images 90 | │ ├── biological.png 91 | │ ├── chemical.png 92 | │ ├── logo.png 93 | │ └── physical.png 94 | ├── R 95 | │ └── render-reports.R 96 | ├── resources 97 | │ ├── styles.css 98 | │ └── word-template.docx 99 | └── soils-demo.Rproj 100 | ``` 101 | 102 |
103 | 104 | -------------------------------------------------------------------------------- /R/map.R: -------------------------------------------------------------------------------- 1 | #' Prep data to gis df 2 | #' 3 | #' @param df Dataframe containing columns: `longitude`, `latitude`, and two 4 | #' columns with values you want to appear in the map label and popup. 5 | #' @param label_heading Column in `df` that you want to appear as the bold point 6 | #' label on your map, as well as the first line of the popup when the user 7 | #' clicks a point. 8 | #' @param label_body Column in `df` that you want to appear as body text below 9 | #' the `label_heading` in the popup. 10 | #' @returns Dataframe to be input into `make_leaflet()`. 11 | #' @export 12 | #' 13 | #' @examples 14 | #' washi_data |> 15 | #' dplyr::distinct(latitude, longitude, .keep_all = TRUE) |> 16 | #' head(3) |> 17 | #' prep_for_map(label_heading = field_name, label_body = crop) |> 18 | #' dplyr::glimpse() 19 | prep_for_map <- function(df, label_heading, label_body) { 20 | testthat::expect_contains(names(df), c("longitude", "latitude")) 21 | 22 | df |> 23 | dplyr::filter(!duplicated(sample_id)) |> 24 | dplyr::arrange(field_id) |> 25 | dplyr::mutate( 26 | dplyr::across(dplyr::where(is.numeric), \(x) round(x, 4)), 27 | label = glue::glue( 28 | "{eval(rlang::expr({{ label_heading }}))}" 29 | ), 30 | popup = glue::glue( 31 | "{label}
{eval(rlang::expr({{ label_body }}))}" 32 | ) 33 | ) 34 | } 35 | 36 | #' Make leaflet map 37 | #' 38 | #' @param df Dataframe containing columns: `longitude`, `latitude`, `label`, 39 | #' `popup`. See `prep_for_map()` for details. 40 | #' @param primary_color Color of points. Defaults to WaSHI red. 41 | #' 42 | #' @source JavaScript code adapted from 43 | #' [leaflet.extras](https://github.com/bhaskarvk/leaflet.extras/tree/master). 44 | #' 45 | #' @returns Leaflet map. 46 | #' 47 | #' @export 48 | #' 49 | #' @examples 50 | #' gis_df <- washi_data |> 51 | #' dplyr::distinct(latitude, longitude, .keep_all = TRUE) |> 52 | #' head(3) |> 53 | #' prep_for_map(label_heading = field_name, label_body = crop) 54 | #' 55 | #' dplyr::glimpse(gis_df) 56 | #' 57 | #' # Make leaflet 58 | #' make_leaflet(gis_df) 59 | make_leaflet <- function( 60 | df, 61 | primary_color = "#a60f2d" 62 | ) { 63 | agol <- "https://server.arcgisonline.com/ArcGIS/rest/services/" 64 | testthat::expect_contains( 65 | names(df), 66 | c("longitude", "latitude", "label", "popup") 67 | ) 68 | 69 | leaflet::leaflet(df) |> 70 | leaflet::addTiles( 71 | urlTemplate = glue::glue( 72 | "{{agol}World_Imagery/MapServer/tile/{z}/{y}/{x}", 73 | .open = "{{" 74 | ), 75 | group = "Satellite" 76 | ) |> 77 | leaflet::addTiles( 78 | urlTemplate = glue::glue( 79 | "{{agol}/World_Topo_Map/MapServer/tile/{z}/{y}/{x}", 80 | .open = "{{" 81 | ), 82 | group = "Topographic" 83 | ) |> 84 | leaflet::addCircleMarkers( 85 | ~longitude, 86 | ~latitude, 87 | label = ~ purrr::map(label, \(x) htmltools::HTML(x)), 88 | labelOptions = leaflet::labelOptions( 89 | noHide = TRUE, 90 | style = list("font-size" = "15px"), 91 | direction = "auto" 92 | ), 93 | popup = ~ purrr::map(popup, \(x) htmltools::HTML(x)), 94 | popupOptions = leaflet::popupOptions(closeOnClick = TRUE), 95 | options = leaflet::markerOptions(riseOnHover = TRUE), 96 | radius = 10, 97 | color = primary_color, 98 | stroke = FALSE, 99 | fillOpacity = 0.7 100 | ) |> 101 | leaflet::addLayersControl( 102 | baseGroups = c("Satellite", "Topographic"), 103 | options = leaflet::layersControlOptions(collapsed = FALSE) 104 | ) |> 105 | leaflet::addEasyButton( 106 | leaflet::easyButton( 107 | icon = "ion-arrow-shrink", 108 | title = "Reset view", 109 | onClick = leaflet::JS( 110 | "function(btn, map){ map.setView(map._initialCenter, map._initialZoom); }" 111 | ) 112 | ) 113 | ) |> 114 | htmlwidgets::onRender(leaflet::JS( 115 | " 116 | function(el, x){ 117 | var map = this; 118 | map.whenReady(function(){ 119 | map._initialCenter = map.getCenter(); 120 | map._initialZoom = map.getZoom(); 121 | }); 122 | }" 123 | )) 124 | } 125 | -------------------------------------------------------------------------------- /inst/templates/english/05_physical-measurements.qmd: -------------------------------------------------------------------------------- 1 | ## [**Physical**]{style="color: #a60f2d"} ![](images/physical.png){height="50px"}\newline\newline 2 | 3 | ***Soil Texture*** is the relative proportion of sand, silt, and clay-sized particles in your soil. Imagine these particles like basketballs, golf balls, and poppy seeds, which are very different in size even though soil particles don't appear different to the naked eye. Importantly, soil texture describes only the mineral portion of the soil and is not affected by organic matter or management. However, soil texture is a significant driver of how soils respond to management. Soils with higher clay content can hold more nutrients, organic matter, and water than sandy soils. This is because clay particles have high surface area and electrical charge and create small soil pores. Soils with high sand content have larger pores, and cannot hold as much water. 4 | 5 | ![](https://raw.githack.com/WA-Department-of-Agriculture/soils/main/figures/ball-texture.png){width="3in" fig-alt="Figure showing size comparisons of soil particles (sand, silt, and clay) to common circular items (basketball, golf ball, and poppy seed)"} 6 | 7 | 8 | 9 | ::: {.content-visible when-format="html"} 10 | ![](https://raw.githack.com/WA-Department-of-Agriculture/soils/main/figures/compaction.png){width="3in" style="float:right" fig-alt="Comparison between uncompacted and compacted soil. Uncompacted soil particles are more spread out, while compacted soil particles are closed together."} 11 | ::: 12 | 13 | ***Bulk Density*** is the mass of particles within a certain volume of soil and is used as an indicator of soil compaction. Bulk density varies depending on soil texture and structure and is greatly affected by tillage, tractor passes, and organic matter inputs. It is a primary determinant of soil aeration, porosity, water infiltration, and root growth. For more information on the special equipment required to measure bulk density, consult this [NRCS protocol](https://www.nrcs.usda.gov/sites/default/files/2022-10/Soil%20Bulk%20Density%20Moisture%20Aeration.pdf "NRCS bulk density protocol"). 14 | 15 | 16 | 17 | ::: {.content-visible unless-format="html"} 18 | ![](https://raw.githack.com/WA-Department-of-Agriculture/soils/main/figures/compaction.png){width="3in" fig-alt="Comparison between uncompacted and compacted soil. Uncompacted soil particles are more spread out, while compacted soil particles are closed together."} 19 | ::: 20 | 21 | ***Infiltration*** measures the rate at which water enters the soil surface. If the infiltration rate is low, water will pond on the surface. This can make it difficult to enter the field and lead to erosion and runoff. High salinity, plow pans, and cemented layers in the soil can lead to poor infiltration and drainage. Soil texture is also a major factor, as large pores created by sand particles quicken infiltration rates while small pores from clay particles slow infiltration rates. Management also plays a role. Excessive tillage can break up soil structure which slows infiltration. Adding organic matter can form soil aggregates, which can quicken infiltration. This indicator is typically measured in the field, as outlined in this [NRCS protocol](https://www.nrcs.usda.gov/sites/default/files/2022-10/Infiltration.pdf "NRCS infiltration protocol"). 22 | 23 | ***Aggregate Stability*** measures the resistance of groups of soil particles, or aggregates, to disintegration. Aggregates are formed when soil particles associate with organic matter, plant roots, fungal hyphae, and "glues" made by soil microorganisms. Water and wind can break down unstable aggregates, while stable aggregates can resist erosion and increase water infiltration, drainage, and storage capacity. Aggregate stability is an excellent example of how biological life impacts soil physical properties. Soils high in clay tend to have higher aggregate stability than sandy soils, but increasing SOM improves aggregate stability across all soil textures. 24 | 25 | ![](https://raw.githack.com/WA-Department-of-Agriculture/soils/main/figures/aggregate-stability.png){width="5.8in" fig-alt="Aggregate held together with organic matter, roots, fungal hyphae, and microbial glues. An arrow with text says aggregate disintegration points toward an aggregate broken apart and text that says particles are more prone to erosion."} 26 | 27 | ***Water Holding Capacity*** (WHC) is the amount of water a soil can hold. WHC describes how the soil will store and supply water during high rainfall events and times of drought. WHC varies by soil texture and bulk density, and can be greatly impacted by management. Generally, soils with finer textures, high organic matter, and low bulk density have higher WHC. 28 | 29 | \[EDIT: ADD A DESCRIPTION OF ANY OTHER PHYSICAL INDICATORS MEASURED IN YOUR PROJECT HERE\] 30 | -------------------------------------------------------------------------------- /R/helpers.R: -------------------------------------------------------------------------------- 1 | #' Calculate the mode of categorical variable 2 | #' 3 | #' @param x Character vector to calculate mode from. 4 | #' 5 | #' @returns The value that occurred most often. 6 | #' 7 | #' @examples 8 | #' calculate_mode(washi_data$crop) 9 | #' 10 | #' @export 11 | #' 12 | 13 | calculate_mode <- function(x) { 14 | uniqx <- unique(stats::na.omit(x)) 15 | uniqx[which.max(tabulate(match(x, uniqx)))] 16 | } 17 | 18 | #' Pull unique values from one column of dataframe 19 | #' 20 | #' @param df Dataframe with column to extract unique values from. 21 | #' @param target Variable to pull unique vector of (i.e. crop or 22 | #' county). 23 | #' 24 | #' @returns Vector of unique values from target column. 25 | #' @examples 26 | #' washi_data |> 27 | #' pull_unique(crop) 28 | #' 29 | #' @export 30 | #' 31 | 32 | pull_unique <- function(df, target) { 33 | df |> 34 | dplyr::pull({{ target }}) |> 35 | unique() 36 | } 37 | 38 | # These functions are used to wrangle data for the table and plot functions in 39 | # producer_report.qmd --------------------------------------------------------- 40 | 41 | #' Calculate n samples and most frequent texture by a grouping variable 42 | #' 43 | #' This function is used in `summarize_by_var`. 44 | #' 45 | #' @param results_long Dataframe in tidy, long format with columns: `sample_id`, 46 | #' `texture`. 47 | #' @param producer_info Vector of producer's values for the grouping variable. 48 | #' @param var Variable to group and summarize by. 49 | #' 50 | get_n_texture_by_var <- function(results_long, producer_info, var) { 51 | testthat::expect_contains(names(results_long), c("sample_id", "texture")) 52 | 53 | results_long |> 54 | dplyr::filter({{ var }} %in% producer_info) |> 55 | dplyr::summarize( 56 | n = dplyr::n_distinct(sample_id), 57 | Texture = calculate_mode(texture), 58 | .by = {{ var }} 59 | ) 60 | } 61 | 62 | #' Summarize producer's samples with averages by grouping variable 63 | #' 64 | #' @param results_long Dataframe in tidy, long format with columns: `sample_id`, 65 | #' `texture`, `measurement_group`, `abbr`, `value`. 66 | #' @param producer_samples Dataframe in tidy, long format with columns: 67 | #' `measurement_group`, `abbr`, `value`. 68 | #' @param var Variable to summarize by. 69 | #' 70 | #' @export 71 | summarize_by_var <- function(results_long, producer_samples, var) { 72 | testthat::expect_contains( 73 | names(producer_samples), 74 | c("measurement_group", "abbr", "value") 75 | ) 76 | 77 | testthat::expect_contains( 78 | names(results_long), 79 | c("sample_id", "texture", "measurement_group", "abbr", "value") 80 | ) 81 | 82 | producer_info <- producer_samples |> 83 | pull_unique({{ var }}) 84 | 85 | n_texture <- get_n_texture_by_var(results_long, producer_info, {{ var }}) 86 | 87 | results_long |> 88 | dplyr::summarize( 89 | value = mean(value, na.rm = TRUE), 90 | .by = c(measurement_group, abbr, {{ var }}) 91 | ) |> 92 | dplyr::filter({{ var }} %in% producer_info) |> 93 | dplyr::left_join(n_texture, by = dplyr::join_by({{ var }})) |> 94 | dplyr::mutate( 95 | "Field or Average" = glue::glue("Average \n({n} Fields)") 96 | ) |> 97 | dplyr::select(-n) |> 98 | tidyr::unite( 99 | "Field or Average", 100 | c({{ var }}, `Field or Average`), 101 | sep = " " 102 | ) 103 | } 104 | 105 | #' Summarize samples across the project 106 | #' 107 | #' @param results_long Dataframe in tidy, long format with columns: `sample_id`, 108 | #' `texture`, `measurement_group`, `abbr`, `value`. 109 | #' 110 | #' @export 111 | summarize_by_project <- function(results_long) { 112 | testthat::expect_contains( 113 | names(results_long), 114 | c("sample_id", "texture", "measurement_group", "abbr", "value") 115 | ) 116 | 117 | n <- dplyr::n_distinct(results_long$sample_id) 118 | 119 | texture <- calculate_mode(results_long$texture) 120 | 121 | results_long |> 122 | dplyr::summarize( 123 | value = mean(value, na.rm = TRUE), 124 | .by = c(measurement_group, abbr) 125 | ) |> 126 | dplyr::mutate( 127 | "Field or Average" = glue::glue("Project Average \n({n} Fields)"), 128 | Texture = texture 129 | ) 130 | } 131 | 132 | #' Get table headers for flextable 133 | #' 134 | #' This function uses the data dictionary to create a new dataframe of the 135 | #' abbreviations and units for each measurement group for flextable 136 | #' 137 | #' @param dictionary Dataframe containing columns `measurement_group`, `abbr`, 138 | #' `unit`. 139 | #' @param group Character `measurement_group` value. 140 | #' 141 | #' @export 142 | get_table_headers <- function(dictionary, group) { 143 | testthat::expect_contains( 144 | names(dictionary), 145 | c("measurement_group", "abbr", "unit") 146 | ) 147 | 148 | dictionary |> 149 | dplyr::filter(measurement_group == group) |> 150 | dplyr::select(abbr, unit) |> 151 | dplyr::mutate(key = abbr, .after = abbr) |> 152 | rbind(c("Field or Average", "Field or Average", "")) 153 | } 154 | -------------------------------------------------------------------------------- /inst/templates/english/06_biological-measurements.qmd: -------------------------------------------------------------------------------- 1 | ## [**Biological**]{style="color: #335c67"} ![](images/biological.png){height="50px"}\newline\newline 2 | 3 | 4 | 5 | ::: {.content-visible when-format="html"} 6 | ![](https://raw.githack.com/WA-Department-of-Agriculture/soils/main/figures/som.png){width="3.5in" style="float:right" fig-alt="Soil Organic Matter (SOM) supports most ecosystems services and soil benefits, but slow to change. There are three layers of circles. The most outer circle says 42% other materials. The next inner circle says 58% total organic carbon. There are two circles inside this circle that says potentially mineralizable carbon (microbial respiration essential for nutrient cycling) and permanganate oxidizable carbon (newly stabilized SOM, responds more quickly to management)."} 7 | ::: 8 | 9 | ***Soil Organic Matter*** (SOM) is the portion of soils not made up of minerals, air, and water, but is instead composed of animal, plant, and microbial matter in various stages of decomposition. SOM is comprised of approximately 58% organic carbon (to convert total organic carbon (TOC) to SOM, an easy rule of thumb is to simply multiply by 2). The remaining portion of SOM includes other essential plant nutrients such as nitrogen, phosphorous, and sulfur. SOM varies by inherent soil and landscape properties such as texture, mineralogy, precipitation, and temperature. It is also greatly impacted by management. To learn more about how to increase SOM, read about the [NRCS principles of building soil health](https://www.nrcs.usda.gov/conservation-basics/natural-resource-concerns/soils/soil-health "NRCS principles of building soil health"). SOM underlies many of the benefits and ecosystem services that soils provide. It has a large impact on almost all other soil properties and is often used as a primary indicator of soil health. However, SOM can be slow to change as the result of management. Because of this, many other indicators have been developed to detect more sensitive components within SOM. Keep reading to learn more. 10 | 11 | 12 | 13 | ::: {.content-visible unless-format="html"} 14 | ![](https://raw.githack.com/WA-Department-of-Agriculture/soils/main/figures/som.png){height="3.5in" fig-alt="Soil Organic Matter (SOM) supports most ecosystems services and soil benefits, but slow to change. There are three layers of circles. The most outer circle says 42% other materials. The next inner circle says 58% total organic carbon. There are two circles inside this circle that says potentially mineralizable carbon (microbial respiration essential for nutrient cycling) and permanganate oxidizable carbon (newly stabilized SOM, responds more quickly to management)."} 15 | ::: 16 | 17 | ***Potentially Mineralizable Carbon*** (MinC, frequently referred to as "Soil Respiration") measures the release of carbon dioxide (CO₂) from soil. This measurement is done in a laboratory incubation under controlled conditions "ideal" for microbes. The term mineralization refers to the process in which soil microbes produce CO₂ as they decompose SOM and plant residues. This process also releases other nutrients, like nitrogen, which can be taken up by crops. Higher MinC represents greater potential biological activity. Soils with lower SOM will have inherently lower MinC, while compacted soils may not provide adequate aeration for the mineralization process. 18 | 19 | ***Permanganate Oxidizable Carbon*** (POXC, once referred to as "Active Carbon") is a fraction of SOM that is more quickly influenced by changes in management (compared to SOM, which can take up to ten years to detect a difference). In this laboratory test, a portion of SOM is decomposed or oxidized by potassium permanganate. POXC levels are often associated with practices that lead to long-term organic matter storage, and may represent a portion of SOM that is from plant material, including compounds related to plant defense. 20 | 21 | ***Potentially Mineralizable Nitrogen*** (PMN) represents the amount of organic nitrogen that can be converted (or "mineralized") to plant-available nitrate or ammonium. This measurement is taken from a laboratory incubation and can help producers estimate how much nitrogen may be released to crops during the growing season. Additional information on the measurement and interpretation of PMN can be found in this [publication from the NRCS](https://www.nrcs.usda.gov/sites/default/files/2022-10/potentially_mineralizable_nitrogen.pdf%22). 22 | 23 | ***ACE Soil Protein*** is the fraction of SOM comprised of proteins from soil microorganisms. Proteins contain nitrogen that can be mineralized for plant uptake, and are therefore an important contributor to crop growth. ACE stands for autoclaved citrate-extractable, which is the laboratory method for extracting the proteins. ACE soil protein is related to aggregate stability as it partly measures proteins that are physically sticky and hold soil particles together. ACE is also sensitive to management changes, so can be a valuable indicator for evaluating relatively short-term changes in soil health. 24 | 25 | \[EDIT: ADD A DESCRIPTION OF ANY OTHER BIOLOGICAL INDICATORS MEASURED IN YOUR PROJECT HERE\] 26 | -------------------------------------------------------------------------------- /data-raw/example_data.R: -------------------------------------------------------------------------------- 1 | # data_dictionary ============================================================== 2 | data_dictionary <- read.csv( 3 | here::here("inst/templates/english/data/data-dictionary.csv"), 4 | check.names = FALSE, 5 | encoding = "UTF-8" 6 | ) 7 | 8 | usethis::use_data(data_dictionary, overwrite = TRUE) 9 | 10 | # washi_data =================================================================== 11 | washi_data <- read.csv( 12 | here::here("inst/templates/english/data/washi-data.csv"), 13 | check.names = FALSE) 14 | 15 | usethis::use_data(washi_data, overwrite = TRUE) 16 | 17 | # df_plot ====================================================================== 18 | 19 | # get producer info 20 | producer <- washi_data |> 21 | dplyr::filter(producer_id == "WUY05") 22 | 23 | # Tidy data into long format and join with data dictionary 24 | results_long <- washi_data |> 25 | dplyr::mutate(dplyr::across(12:42, as.numeric)) |> 26 | tidyr::pivot_longer( 27 | cols = 12:42, 28 | names_to = "measurement" 29 | ) |> 30 | dplyr::inner_join(data_dictionary, by = c("measurement" = "column_name")) |> 31 | dplyr::arrange(measurement_group, order) |> 32 | dplyr::mutate( 33 | abbr = factor( 34 | abbr, 35 | levels = data_dictionary$abbr, 36 | ordered = is.ordered(data_dictionary$order) 37 | ), 38 | abbr_unit = factor( 39 | abbr_unit, 40 | levels = data_dictionary$abbr_unit, 41 | ordered = is.ordered(data_dictionary$order) 42 | ) 43 | ) |> 44 | dplyr::filter(!is.na(value)) 45 | 46 | df_plot <- results_long |> 47 | dplyr::mutate( 48 | # Dummy column to set x-axis in same place for each facet 49 | dummy = "dummy", 50 | # Set category to group samples 51 | category = dplyr::case_when( 52 | sample_id %in% producer$sample_id ~ "Your fields", 53 | crop %in% producer$crop ~ "Same crop", 54 | county %in% producer$county ~ "Same county", 55 | .default = "Other fields" 56 | ), 57 | # Set category factors so producer samples are plotted last 58 | category = factor( 59 | category, 60 | levels = c("Your fields", "Same crop", "Same county", "Other fields") 61 | ), 62 | # Label for tooltip 63 | label = dplyr::case_when( 64 | category == "Your fields" ~ glue::glue( 65 | "{field_name}
{crop}
{value} {unit}" 66 | ), 67 | .default = glue::glue( 68 | "{county}
", 69 | "{crop}
", 70 | "{value} {unit}" 71 | ) 72 | ) 73 | ) 74 | 75 | # Order the df so producer's points are plotted on top 76 | df_plot <- df_plot[order(df_plot$category, decreasing = TRUE), ] 77 | 78 | saveRDS(df_plot, here::here("inst/extdata/df_plot.RDS")) 79 | 80 | # tables ======================================================================= 81 | 82 | producer_samples <- results_long |> 83 | dplyr::filter(producer_id == "WUY05" & year == 2023) 84 | 85 | # Calculate averages by crop, county, and project 86 | crop_summary <- soils::summarize_by_var( 87 | results_long, 88 | producer_samples, 89 | var = crop 90 | ) 91 | 92 | county_summary <- soils::summarize_by_var( 93 | results_long, 94 | producer_samples, 95 | var = county 96 | ) 97 | 98 | project_summary <- soils::summarize_by_project(results_long) 99 | 100 | producer_table <- producer_samples |> 101 | dplyr::select( 102 | measurement_group, 103 | abbr, 104 | value, 105 | "Field or Average" = field_name, 106 | Texture = texture 107 | ) 108 | 109 | # Bind together into one df and round values to 2 digits 110 | df_table <- dplyr::bind_rows( 111 | producer_table, 112 | crop_summary, 113 | county_summary, 114 | project_summary 115 | ) |> 116 | dplyr::mutate( 117 | value = as.numeric(formatC(value, 2, drop0trailing = TRUE)) 118 | ) 119 | 120 | # Split into list with each measurement group as its own df and pivot wider 121 | groups <- df_table |> 122 | split(df_table$measurement_group) |> 123 | purrr::map(\(x) { 124 | tidyr::pivot_wider( 125 | x, 126 | id_cols = c("Field or Average", Texture), 127 | names_from = abbr 128 | ) 129 | }) 130 | 131 | # Special wrangling for texture 132 | 133 | # Extract physical df from averages list 134 | physical <- list(physical = groups$physical) 135 | 136 | # Remove texture from all dataframes except physical 137 | groups <- purrr::map( 138 | subset( 139 | groups, 140 | !(names(groups) == "physical") 141 | ), 142 | \(x) dplyr::select(x, -Texture) 143 | ) 144 | 145 | # Add physical df back to the averages list 146 | groups <- c(groups, physical) 147 | 148 | # Delete any county or crop averages where n = 1 149 | tables <- groups |> 150 | purrr::map( 151 | subset, 152 | !grepl("(1 Fields)", `Field or Average`) 153 | ) 154 | 155 | saveRDS(tables, here::here("inst/extdata/tables.RDS")) 156 | 157 | # headers ====================================================================== 158 | 159 | # Map function to each measurement group, resulting in a new df with 160 | # abbreviations and units in a list for make_ft() 161 | headers <- results_long |> 162 | soils::pull_unique(target = measurement_group) |> 163 | as.list() |> 164 | rlang::set_names() |> 165 | purrr::map(\(group) get_table_headers(data_dictionary, group)) 166 | 167 | saveRDS(headers, here::here("inst/extdata/headers.RDS")) 168 | -------------------------------------------------------------------------------- /vignettes/customize.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Customize & write" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Customize & write} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | ```{r, include = FALSE} 11 | knitr::opts_chunk$set( 12 | collapse = TRUE, 13 | comment = "#>" 14 | ) 15 | ``` 16 | 17 | Now that you have imported your own data, it's time to customize the report 18 | content and style. 19 | 20 | Places to customize and change content are marked with the text "`EDIT:`". Find 21 | all edit markers in the RStudio project with `Ctrl` + `Shift` + `F` to open the 22 | `Find in Files` wizard. 23 | 24 | # Report metadata and options 25 | 26 | The report metadata and options are set in the YAML and setup chunk in 27 | `01_producer-report.qmd`. 28 | 29 | Start with the YAML (Yet Another Markup Language) header, which is the content 30 | sandwiched between three dashes (`---`) at the top of the file. It contains 31 | document metadata, parameters, and customization options. 32 | 33 | The only fields you need to edit are: 34 | 35 | - **`title`** is what appears at the very top of the report. The logo appears 36 | above the title text (see the [markdown 37 | primer](https://wa-department-of-agriculture.github.io/soils/articles/markdown.html) 38 | for help with image syntax). 39 | 40 | - **`subtitle`** appears below the title toward the right side. 41 | 42 | - **`params`** define the parameter values used when iteratively rendering the 43 | report with the RStudio `Render` button. They must be an existing 44 | combination of producer ID and year that have sample results in your data. 45 | 46 | - **`producer_id`** choose a producer ID in your data that you want to 47 | render the report for. 48 | 49 | - **`year`** choose the year of the samples for the chosen producer ID to 50 | include in the report. 51 | 52 |
53 | 54 | Example changed YAML 55 | 56 | ``` yaml 57 | # EDIT: Replace logo.png in images folder with your own and add project name. 58 | title: "![](images/beautiful-soil.png) The Best Soil Health Survey" 59 | # EDIT: Subtitle right aligned below title. 60 | subtitle: "Results from 2024" 61 | # EDIT: Choose a valid producer_id/year combo that exists in your dataset. 62 | params: 63 | producer_id: "Sammy Sunflower" 64 | year: 2024 65 | ``` 66 | 67 |
68 | 69 | Ignore the other YAML fields and values until you would like to explore other 70 | ways of customizing your reports. Learn about the available YAML fields for 71 | [HTML documents](https://quarto.org/docs/reference/formats/html.html) and [MS 72 | Word documents](https://quarto.org/docs/reference/formats/docx.html). 73 | 74 | # Report content 75 | 76 | `01_producer-report.qmd` uses the Quarto 77 | [`{{< include >}}`](https://quarto.org/docs/authoring/includes.html) shortcode 78 | to embed content within the main parameterized report. 79 | 80 | Edit the following Quarto files to fit your project and adjust/remove soil 81 | measurements that were tested. 82 | 83 | ``` 84 | ├── 03_project-summary.qmd 85 | ├── 04_soil-health-background.qmd 86 | ├── 05_physical-measurements.qmd 87 | ├── 06_biological-measurements.qmd 88 | ├── 07_chemical-measurements.qmd 89 | ├── 08_looking-forward.qmd 90 | ``` 91 | 92 | Under the `Project Results` heading in `01_producer-report.qmd`, update the 93 | sample depth: 94 | 95 | > All samples were collected from [EDIT: SOIL DEPTH (e.g. 0-6 inches, or 0-30 96 | > cm)]. 97 | 98 | `01_producer-report.qmd` calls `02_secion-template.qmd` as a child document to 99 | generate a section for each `measurement_group` defined in the 100 | `data-dictionary.csv`. You shouldn't need to edit `02_secion-template.qmd` 101 | unless you want more advanced customization. 102 | 103 | # Style and theme 104 | 105 | The look and feel of your reports can be customized by changing the fonts and 106 | colors to match your branding. The plot and table outputs are controlled by the 107 | `set-fonts-colors` chunk in `01_producer-report.qmd`. HTML reports are styled by 108 | the `styles.css` file. MS Word reports are styled using the `word-template.docx` 109 | template file. 110 | 111 | ## `set-fonts-colors` chunk 112 | 113 | The fonts and colors used in the tables and plots of the report are defined in 114 | this chunk. Change these values to match your own branding. 115 | 116 | ## Style sheets 117 | 118 | The style sheets can be found in the `resources` directory and edited to 119 | customize the report appearance to match your own branding. 120 | 121 | ### HTML 122 | 123 | `styles.css` controls the appearance of HTML reports. Learn more about 124 | [CSS](https://quarto.org/docs/visual-editor/content.html#css-styles). 125 | 126 | ``` 127 | /* Edit these :root variables */ 128 | :root { 129 | --primary-color: #023B2C; 130 | --secondary-color: #335c67; 131 | --link-color: #a60f2d; 132 | --light-color: #F2F0E6; 133 | --fg-color: white; /* color for text with colored background*/ 134 | --heading-font: "Georgia"; 135 | --body-font: "Arial"; 136 | } 137 | ``` 138 | 139 | ### MS Word 140 | 141 | Open `word-template.docx` and modify the styles according to [Quarto 142 | documentation](https://quarto.org/docs/output-formats/ms-word-templates.html) 143 | and [Microsoft 144 | documentation](https://support.microsoft.com/en-gb/office/customize-or-create-new-styles-d38d6e47-f6fc-48eb-a607-1eb120dec563). 145 | -------------------------------------------------------------------------------- /inst/templates/english/07_chemical-measurements.qmd: -------------------------------------------------------------------------------- 1 | ## [**Chemical**]{style="color: #d4820a"} ![](images/chemical.png){height="50px"}\newline\newline 2 | 3 | ***Plant Essential Nutrients*** include both macronutrients such as nitrogen (N), phosphorous (P), potassium (K), calcium (Ca), magnesium (Mg), and sulfur (S), and micronutrients (required in comparatively smaller amounts) such as iron (Fe), zinc (Zn), copper (Cu), boron (B), and manganese (Mn). These elements are typically reported in parts per million, which is equivalent to milligrams per kilogram (1 ppm = 1 mg/kg). Each of these elements are required for crop production, though the 4 Rs---or the right quantity, right timing, right placement, and right source---will vary depending on the crop. While many of these nutrients are inherent in the soil, some must be added. Careful consideration should be given to balancing and replenishing plant essential nutrients via soil health building practices and principles. More information on plant essential nutrients can be found in this [Oregon State University Soil Test Interpretation Guide](https://catalog.extension.oregonstate.edu/ec1478 "Oregon State University Soil Test Interpretation Guide"). 4 | 5 | ***Soil pH*** describes how acidic (pH less than 7.0) or alkaline (pH greater than 7.0) the soil is, and is a measure of the concentration of hydrogen ions in the soil solution. Many essential nutrients like P, Fe, Mn, Zn, Cu, Co, and B become less plant-available at alkaline pHs. Other nutrients like Al or B can become toxic at acidic pHs. Soil pH also greatly affects what microbial populations can live in the soil. Soil pH is impacted by inherent qualities of the soil such as its age, mineralogy, and rainfall zone. It is also impacted by fertilization, irrigation water pH, and SOM content. Most agricultural crops grow best in neutral soil pHs, within a range of 6 to 8. Soil pH can be lowered using sulfur or raised by adding agricultural lime. 6 | 7 | ***Electrical Conductivity*** (EC) measures the concentration of salts in the soil. Excessive salts can stress plants and lower crop yield and quality, as well as impact soil structure, infiltration rates, and water holding capacity. In particular, sodium (Na) can cause crusting and dispersion of soil particles, leading to surface runoff and erosion. Crops in sodium-affected soils (sodic soils) may also have challenges taking up other essential salts such as Ca, Mg, and K. 8 | 9 | ***Cation Exchange Capacity*** (CEC) describes the soil's ability to hold a slow-release reservoir of nutrients, as positively charged ions (e.g., NH^~4~+^, K^+^, Ca^2+^, Mg^2+^) in the soil are held by negatively charged sites on clay particles and SOM. While CEC is determined in part by soil texture, increasing SOM can greatly increase CEC. Sandy loam soils typically have CECs ranging from 1 to 10 meq/100 g, loam soils range from 5 to 15 meq/100 g, and clay soils have CECs greater than 30 meq/100 g. SOM can provide an additional 200 to 400 meq/100 g (note that CEC units may be reported differently, but 1 meq/100g = 1 cmolc/kg). Soil pH can also alter the CEC of organic matter and clay particles, further underscoring the impact of pH on other soil measurements. 10 | 11 | 12 | 13 | ::: {.content-visible when-format="html"} 14 | ![](https://raw.githack.com/WA-Department-of-Agriculture/soils/main/figures/tn.png){width="3.5in" style="float:right" fig-alt="Total Nitrogen (TN) measures different forms of nitrogen in the soil and is closely related to soil productivity. There is a large circle with two smaller circles inside that are labeled Organic N pools (not available, but can be made available during the growing season through microbial processing) and Inorganic N pools (changes very quickly and should be measured often but plant available). Inside the Organic N pools circle are two more circles labeled potentially mineralizable nitrogen and ACE soil protein. Inside the Inorganic N pools circle are two more circles labeled nitrate and ammonium."} 15 | ::: 16 | 17 | ***Total Nitrogen*** is a measurement of both inorganic (plant-available nitrate and ammonium) and organic (typically not plant-available) nitrogen in the soil. Having sufficient total nitrogen in the soil is key for promoting mineralization, or the process of changing the organic nitrogen to a form that plants can use. 18 | 19 | 20 | 21 | ::: {.content-visible unless-format="html"} 22 | ![](https://raw.githack.com/WA-Department-of-Agriculture/soils/main/figures/tn.png){height="3.5in" fig-alt="Total Nitrogen (TN) measures different forms of nitrogen in the soil and is closely related to soil productivity. There is a large circle with two smaller circles inside that are labeled Organic N pools (not available, but can be made available during the growing season through microbial processing) and Inorganic N pools (changes very quickly and should be measured often but plant available). Inside the Organic N pools circle are two more circles labeled potentially mineralizable nitrogen and ACE soil protein. Inside the Inorganic N pools circle are two more circles labeled nitrate and ammonium."} 23 | ::: 24 | 25 | ***Inorganic Carbon***, frequently called carbonates, is present in some soils, mostly in arid environments. Carbonates can be an important source of nutrients and carbon storage in soils, but in excess can lead to challenges with salinity and poor infiltration. While some strategies can be employed to increase or decrease carbonates in soil, they are generally considered less sensitive to management than organic carbon. As such, most discussions of agricultural management focus only on organic carbon. 26 | 27 | \[EDIT: ADD A DESCRIPTION OF ANY OTHER CHEMICAL INDICATORS MEASURED IN YOUR PROJECT HERE\] 28 | -------------------------------------------------------------------------------- /inst/templates/spanish/06_biological-measurements.qmd: -------------------------------------------------------------------------------- 1 | ## [**Biológico**]{style="color: #335c67"} ![](images/biological.png){height="50px"}\newline\newline 2 | 3 | 4 | 5 | ::: {.content-visible when-format="html"} 6 | ![](https://raw.githack.com/WA-Department-of-Agriculture/soils/main/figures/som-spanish.png){width="3.5in" 7 | style="float:right" 8 | fig-alt="La materia orgánica del suelo (SOM) respalda la mayoría de los servicios de los ecosistemas y los beneficios del suelo, pero su cambio es lento. Hay tres capas de círculos. El círculo más exterior dice 42% otros materiales. El siguiente círculo interior dice 58% de carbono orgánico total. Hay dos círculos dentro de este círculo que dicen carbono potencialmente mineralizable (respiración microbiana esencial para el ciclo de los nutrientes) y carbono oxidable con permanganato (SOM recientemente estabilizada, responde más rápidamente al ser manejado)."} 9 | ::: 10 | 11 | ***La materia orgánica del suelo*** (SOM) es la porción de los suelos que no 12 | está formada por minerales, aire y agua, sino que está compuesta por materia 13 | animal, vegetal y microbiana en varias etapas de descomposición. El SOM se 14 | compone de alrededor de un 58 % de carbono orgánico (TOC) (una regla general 15 | fácil es multiplicar por 2). La porción restante de SOM incluye otros nutrientes 16 | esenciales para las plantas, como nitrógeno, fósforo y azufre. El SOM varía 17 | según las propiedades inherentes del suelo y del paisaje, como la textura, la 18 | mineralogía, la precipitación y la temperatura. También se ve muy afectado por 19 | la gestión. Para obtener más información sobre cómo aumentar la SOM, lea sobre 20 | los [principios de NRCS para mejorar la salud del 21 | suelo](https://www.nrcs.usda.gov/conservation-basics/natural-resource-concerns/soils/soil-health). 22 | La SOM es la base de muchos de los beneficios y servicios ecosistémicos que 23 | proporcionan los suelos. Tiene un gran impacto en casi todas las demás 24 | propiedades del suelo y, a menudo, se usa como indicador primario de la salud 25 | del suelo. Sin embargo, SOM puede tardar en cambiar como resultado de la 26 | gestión. Debido a esto, se han desarrollado muchos otros indicadores para 27 | detectar componentes más sensibles dentro del SOM. Sigue leyendo para saber más. 28 | 29 | 30 | 31 | ::: {.content-visible unless-format="html"} 32 | ![](https://raw.githack.com/WA-Department-of-Agriculture/soils/main/figures/som-spanish.png){height="3.5in" 33 | fig-alt="La materia orgánica del suelo (SOM) respalda la mayoría de los servicios de los ecosistemas y los beneficios del suelo, pero su cambio es lento. Hay tres capas de círculos. El círculo más exterior dice 42% otros materiales. El siguiente círculo interior dice 58% de carbono orgánico total. Hay dos círculos dentro de este círculo que dicen carbono potencialmente mineralizable (respiración microbiana esencial para el ciclo de los nutrientes) y carbono oxidable con permanganato (SOM recientemente estabilizada, responde más rápidamente al ser manejado)."} 34 | ::: 35 | 36 | ***El carbono potencialmente mineralizable*** (MinC, a menudo denominado 37 | "respiración del suelo") mide la liberación de dióxido de carbono (CO₂) del 38 | suelo. Esta medición se realiza en una incubación de laboratorio bajo 39 | condiciones controladas "ideales" para los microbios. El término mineralización 40 | se refiere al proceso en el que los microbios del suelo producen CO₂ a medida 41 | que descomponen la SOM y los residuos vegetales. Este proceso también libera 42 | otros nutrientes, como el nitrógeno, que pueden ser absorbidos por los cultivos. 43 | Un MinC más alto representa una mayor actividad biológica potencial. Los suelos 44 | con un SOM más bajo tendrán un MinC inherentemente más bajo, mientras que los 45 | suelos compactados pueden no proporcionar una aireación adecuada para el proceso 46 | de mineralización. 47 | 48 | ***El carbono oxidable de permanganato*** (POXC, una vez denominado "carbón 49 | activo") es una fracción de SOM que se ve fácilmente influenciada por los 50 | cambios en el manejo (en comparación con el SOM, que puede tardar hasta diez 51 | años en detectar una diferencia). En esta prueba de laboratorio, una porción de 52 | SOM se descompone u oxida con permanganato de potasio. Esta prueba mide una 53 | parte de la SOM que está recién estabilizada y puede ser un signo temprano de 54 | almacenamiento de carbono a largo plazo. 55 | 56 | ***El nitrógeno potencialmente mineralizable*** (PMN) representa la cantidad de 57 | nitrógeno orgánico que se puede convertir (o "mineralizar") en nitrato o amonio 58 | disponible para las plantas. Esta medición se toma de una incubación de 59 | laboratorio y puede ayudar a los productores a estimar la cantidad de nitrógeno 60 | que se puede liberar a los cultivos durante la temporada de crecimiento. Se 61 | puede encontrar información adicional sobre la medición e interpretación de PMN 62 | en esta [publicación del 63 | NRCS](https://www.nrcs.usda.gov/sites/default/files/2022-10/potentially_mineralizable_nitrogen.pdf). 64 | 65 | ***La proteína del suelo ACE*** es la fracción de SOM compuesta por proteínas de 66 | microorganismos del suelo. Las proteínas contienen nitrógeno que puede 67 | mineralizarse para la absorción de las plantas y, por lo tanto, contribuyen de 68 | manera importante al crecimiento de los cultivos. ACE son las siglas de 69 | autoclave citrate-extraable, que es el método de laboratorio para extraer 70 | proteínas. La proteína del suelo ACE se relaciona con la estabilidad de los 71 | agregados, ya que mide las proteínas que son pegajosas y mantienen unidas las 72 | partículas del suelo. La ECA también es sensible a los cambios de manejo, por lo 73 | que puede ser un indicador valioso para evaluar los cambios a corto plazo en la 74 | salud del suelo. 75 | 76 | \[EDIT: ADD A DESCRIPTION OF ANY OTHER BIOLOGICAL INDICATORS MEASURED IN YOUR 77 | PROJECT HERE\] 78 | 79 | -------------------------------------------------------------------------------- /inst/templates/spanish/05_physical-measurements.qmd: -------------------------------------------------------------------------------- 1 | ## [**Físico**]{style="color: #a60f2d"} ![](images/physical.png){height="50px"}\newline\newline 2 | 3 | ***Textura del suelo*** es la proporción relativa de partículas del tamaño de 4 | arena, limo y arcilla en el suelo. Imagínese estas partículas como pelotas de 5 | baloncesto, pelotas de golf y semillas de amapola, que son muy diferentes en 6 | tamaño a pesar de que las partículas del suelo no parecen diferentes a simple 7 | vista. Es importante destacar que la textura del suelo describe solo la parte 8 | mineral del suelo y no se ve afectada por la materia orgánica o el manejo. Sin 9 | embargo, la textura del suelo es un factor importante de cómo responden los 10 | suelos al manejo. Los suelos con mayor contenido de arcilla pueden contener más 11 | nutrientes, materia orgánica y agua que los suelos arenosos. Esto se debe a que 12 | las partículas de arcilla tienen una gran superficie y carga eléctrica y crean 13 | pequeños poros en el suelo. Los suelos con alto contenido de arena tienen poros 14 | más grandes y no pueden retener tanta agua. 15 | 16 | ![](https://raw.githack.com/WA-Department-of-Agriculture/soils/main/figures/ball-texture-spanish.png){width="3in" 17 | fig-alt="Figura que muestra comparaciones de tamaño de partículas de suelo (arena, limo y arcilla) con elementos circulares comunes (baloncesto, pelota de golf y semillas de amapola)"} 18 | 19 | 20 | 21 | ::: {.content-visible when-format="html"} 22 | ![](https://raw.githack.com/WA-Department-of-Agriculture/soils/main/figures/compaction-spanish.png){width="3in" 23 | style="float:right" 24 | fig-alt="Comparación entre suelo no compactado y compactado. Las partículas de suelo no compactadas están más dispersas, mientras que las partículas de suelo compactadas están cerradas entre sí."} 25 | ::: 26 | 27 | ***La densidad aparente*** es la masa de partículas de un cierto volumen de 28 | suelo y se utiliza como indicador de la compactación del suelo. La densidad 29 | aparente varía según la textura y estructura del suelo y se ve muy afectado por 30 | la labranza, las pasadas de tractor y los aportes de materia orgánica. Es un 31 | determinante primario de la aireación del suelo, la porosidad, la infiltración 32 | de agua y el crecimiento de las raíces. Para obtener más información sobre el 33 | equipo especial necesario para medir la densidad aparente, consulte este 34 | [protocolo 35 | NRCS](https://www.nrcs.usda.gov/sites/default/files/2022-10/Soil%20Bulk%20Density%20Moisture%20Aeration.pdf). 36 | 37 | 38 | 39 | ::: {.content-visible unless-format="html"} 40 | ![](https://raw.githack.com/WA-Department-of-Agriculture/soils/main/figures/compaction-spanish.png){width="3in" 41 | fig-alt="Comparación entre suelo no compactado y compactado. Las partículas de suelo no compactadas están más dispersas, mientras que las partículas de suelo compactadas están cerradas entre sí."} 42 | ::: 43 | 44 | ***La infiltración*** mide la velocidad a la que el agua entra en la superficie 45 | del suelo. Si la tasa de infiltración es baja, el agua se acumulará en la 46 | superficie. Esto puede dificultar la entrada en el campo y provocar erosión y 47 | escorrentía. La alta salinidad, las bandejas de arado y las capas cementadas en 48 | el suelo pueden provocar una infiltración y un drenaje deficientes. La textura 49 | del suelo también es un factor importante, ya que los poros grandes creados por 50 | las partículas de arena aceleran las tasas de infiltración, mientras que los 51 | poros pequeños de las partículas de arcilla ralentizan las tasas de 52 | infiltración. La gestión también juega un papel importante. La labranza excesiva 53 | puede romper la estructura del suelo, lo que ralentiza la infiltración. La 54 | adición de materia orgánica puede formar agregados en el suelo, lo que puede 55 | acelerar la infiltración. Por lo general, este indicador se mide en el campo, 56 | como se describe en este [protocolo 57 | NRCS](https://www.nrcs.usda.gov/sites/default/files/2022-10/Infiltration.pdf). 58 | 59 | ***La estabilidad de agregados*** mide la resistencia de grupos de partículas 60 | del suelo, o agregados, a la desintegración. Los agregados se forman cuando las 61 | partículas del suelo se asocian con materia orgánica, raíces de plantas, hifas 62 | fúngicas y "pegamentos" hechos por microorganismos del suelo. El agua y el 63 | viento pueden descomponer los agregados inestables, mientras que los agregados 64 | estables pueden resistir la erosión y aumentar la infiltración de agua, el 65 | drenaje y la capacidad de almacenamiento. La estabilidad de los agregados es un 66 | excelente ejemplo de cómo la vida biológica afecta las propiedades físicas del 67 | suelo. Los suelos con alto contenido de arcilla tienden a tener una mayor 68 | estabilidad de los agregados que los suelos arenosos, pero el aumento de la 69 | materia orgánica del suelo mejora la estabilidad de los agregados en todas las 70 | texturas del suelo, mientras que el contenido de arena inherentemente alto 71 | reduce la estabilidad de los agregados. 72 | 73 | ![](https://raw.githack.com/WA-Department-of-Agriculture/soils/main/figures/aggregate-stability-spanish.png){width="5.8in" 74 | fig-alt="Agregado mantenido unido con materia orgánica, raíces, hifas de hongos y pegamentos microbianos. Una flecha con texto que dice desintegración de agregados apunta hacia un agregado roto y un texto que dice partículas más propensas a la erosión."} 75 | 76 | ***Capacidad de retención de agua*** (WHC) es la cantidad de agua que puede 77 | contener un suelo. El WHC describe cómo el suelo almacenará y suministrará agua 78 | durante eventos de alta precipitación y épocas de sequía. El WHC varía según la 79 | textura del suelo y la densidad aparente y puede verse muy afectado por el 80 | manejo. Generalmente, los suelos con texturas más finas, alta materia orgánica y 81 | baja densidad aparente tienen un WHC más alto. 82 | 83 | \[EDIT: ADD A DESCRIPTION OF ANY OTHER PHYSICAL INDICATORS MEASURED IN YOUR 84 | PROJECT HERE\] 85 | -------------------------------------------------------------------------------- /inst/templates/spanish/07_chemical-measurements.qmd: -------------------------------------------------------------------------------- 1 | ## [**Químico**]{style="color: #d4820a"} ![](images/chemical.png){height="50px"}\newline\newline 2 | 3 | ***Los nutrientes esenciales de las plantas*** incluyen macronutrientes como el 4 | nitrógeno (N), el fósforo (P), el potasio (K), el calcio (Ca), el magnesio (Mg) 5 | y el azufre (S), y los micronutrientes (requeridos en cantidades 6 | comparativamente más pequeñas) como el hierro (Fe), el zinc (Zn), el cobre (C), 7 | el boro (B) y el manganeso (Mn). Por lo general, estos elementos se expresan en 8 | partes por millón, lo que equivale a miligramos por kilogramo (1 ppm = 1 mg/kg). 9 | Cada uno de estos elementos es necesario para la producción de cultivos, aunque 10 | las 4 R, o la cantidad correcta, el momento correcto, la ubicación y la fuente 11 | correctas, variarán según el cultivo. Si bien muchos de estos nutrientes son 12 | inherentes al suelo, algunos deben agregarse. Se debe prestar especial atención 13 | al equilibrio y la reposición de los nutrientes esenciales de las plantas a 14 | través de las prácticas y principios de construcción de la salud del suelo. 15 | Puede encontrar más información sobre los nutrientes esenciales para las plantas 16 | en esta [Guía de interpretación de pruebas de suelo de Universidad Estatal de 17 | Oregón](https://catalog.extension.oregonstate.edu/ec1478). 18 | 19 | ***El pH del suelo*** describe qué tan ácido (pH menor a 7.0) o alcalino (pH 20 | mayor que 7.0) es el suelo, y es una medida de la concentración de iones de 21 | hidrógeno en la solución del suelo. Muchos nutrientes esenciales como P, Fe, Mn, 22 | Zn, Cu, Co y B se vuelven menos disponibles para las plantas a pH alcalinos. 23 | Otros nutrientes como el Al o el B pueden volverse tóxicos a pH ácidos. El pH 24 | del suelo también afecta a las poblaciones microbianas que pueden vivir en el 25 | suelo. El pH del suelo se ve afectado por las cualidades inherentes del suelo, 26 | como su edad, mineralogía y zona de lluvia. También se ve afectado por la 27 | fertilización, el pH del agua de riego y el contenido de SOM. La mayoría de los 28 | cultivos agrícolas crecen mejor en pH neutros del suelo, dentro de un rango de 6 29 | a 8. El pH del suelo puede reducirse con azufre o aumentarse añadiendo cal 30 | agrícola. 31 | 32 | ***Conductividad eléctrica*** (EC) mide la concentración de sales en el suelo. 33 | El exceso de sales puede estresar a las plantas y reducir el rendimiento y la 34 | calidad de los cultivos, así como afectar la estructura del suelo, las tasas de 35 | infiltración y la capacidad de retención de agua. El sodio (Na) puede causar 36 | costras y dispersión de partículas del suelo, lo que conduce a la escorrentía 37 | superficial y la erosión. Los cultivos en suelos afectados por el sodio (suelos 38 | sódicos) también pueden tener dificultades para absorber otras sales esenciales 39 | como Calcio, Magnesio y Potasio. 40 | 41 | ***Capacidad de intercambio catiónico*** (CEC) describe la capacidad del suelo 42 | para retener un reservorio de nutrientes de liberación lenta, ya que los iones 43 | cargados positivamente (por ejemplo, NH4+, K+, Ca2+, Mg2+) en el suelo son 44 | retenidos por sitios cargados negativamente en partículas de arcilla y MOS. Si 45 | bien la CIC está determinada en parte por la textura del suelo, el aumento de la 46 | SOM puede aumentar en gran medida la CIC. Los suelos franco arenosos suelen 47 | tener CIC que oscilan entre 1 y 10 meq/100 g, los suelos francos oscilan entre 5 48 | y 15 meq/100 g, y los suelos arcillosos tienen CIC superiores a 30 meq/100 g. La 49 | SOM puede proporcionar 200 a 400 meq/100 g adicionales (tenga en cuenta que las 50 | unidades de CIC pueden informarse de manera diferente, pero 1 meq/100 g = 1 51 | cmolc/kg). El pH del suelo también puede alterar la CIC de la materia orgánica y 52 | las partículas de arcilla, lo que subraya aún más el impacto del pH en otras 53 | mediciones del suelo. 54 | 55 | 56 | 57 | ::: {.content-visible when-format="html"} 58 | ![](https://raw.githack.com/WA-Department-of-Agriculture/soils/main/figures/tn-spanish.png){width="3.5in" 59 | style="float:right" 60 | fig-alt="El nitrógeno total (TN) mide diferentes formas de nitrógeno en el suelo y está estrechamente relacionado con la productividad del suelo. Hay un círculo grande con dos círculos más pequeños en el interior que están etiquetados como depósitos de N orgánico (no disponibles, pero pueden estar disponibles durante la temporada de crecimiento mediante procesamiento microbiano) y depósitos de N inorgánico (cambian muy rápidamente y deben medirse con frecuencia, pero la planta está disponible). . Dentro del círculo de depósitos de N orgánico hay dos círculos más etiquetados como nitrógeno potencialmente mineralizable y proteína de suelo ACE. Dentro del círculo de depósitos de N inorgánico hay dos círculos más etiquetados como nitrato y amonio."} 61 | ::: 62 | 63 | ***Nitrógeno total*** es una medida del nitrógeno inorgánico (nitrato y amonio 64 | disponibles para las plantas) y orgánico (normalmente no disponible para las 65 | plantas) en el suelo. Tener suficiente nitrógeno total en el suelo es clave para 66 | promover la mineralización, o el proceso de cambiar el nitrógeno orgánico a una 67 | forma que las plantas puedan usar. 68 | 69 | 70 | 71 | ::: {.content-visible unless-format="html"} 72 | ![](https://raw.githack.com/WA-Department-of-Agriculture/soils/main/figures/tn-spanish.png){height="3.5in" 73 | fig-alt="El nitrógeno total (TN) mide diferentes formas de nitrógeno en el suelo y está estrechamente relacionado con la productividad del suelo. Hay un círculo grande con dos círculos más pequeños en el interior que están etiquetados como depósitos de N orgánico (no disponibles, pero pueden estar disponibles durante la temporada de crecimiento mediante procesamiento microbiano) y depósitos de N inorgánico (cambian muy rápidamente y deben medirse con frecuencia, pero la planta está disponible). . Dentro del círculo de depósitos de N orgánico hay dos círculos más etiquetados como nitrógeno potencialmente mineralizable y proteína de suelo ACE. Dentro del círculo de depósitos de N inorgánico hay dos círculos más etiquetados como nitrato y amonio."} 74 | ::: 75 | 76 | ***El carbono inorgánico***, llamado carbonato, está presente en algunos suelos, 77 | sobre todo en ambientes áridos. Los carbonatos pueden ser una fuente importante 78 | de nutrientes y almacenamiento de carbono en los suelos, pero en exceso pueden 79 | provocar problemas de salinidad y mala infiltración. Si bien se pueden emplear 80 | algunas estrategias para aumentar o disminuir los carbonatos en el suelo, 81 | generalmente se consideran menos sensibles al manejo que el carbón orgánico. 82 | Como tal, la mayoría de las discusiones sobre el manejo agrícola se centran solo 83 | en el carbón orgánico. 84 | 85 | \[EDIT: ADD A DESCRIPTION OF ANY OTHER CHEMICAL INDICATORS MEASURED IN YOUR 86 | PROJECT HERE\] 87 | -------------------------------------------------------------------------------- /R/tables.R: -------------------------------------------------------------------------------- 1 | #' Conditional formatting of flextable background cell colors 2 | #' 3 | #' Color the background cells based on how the value compares to the project 4 | #' average. The project average must be the last row of the table. A footnote is 5 | #' added to the table describing what the dark and light colors mean. 6 | #' 7 | #' @param ft Flextable object 8 | #' @param lighter_color Lighter background color. Defaults to WaSHI cream. 9 | #' @param darker_color Darker background color. Defaults to WaSHI tan. 10 | #' @param language Language of the footnote. "English" (default) or "Spanish". 11 | #' 12 | #' @export 13 | #' 14 | #' @examples 15 | #' # Read in wrangled example table data 16 | #' tables_path <- soils_example("tables.RDS") 17 | #' tables <- readRDS(tables_path) 18 | #' 19 | #' # Make the table 20 | #' ft <- flextable::flextable(tables$biological) 21 | #' ft 22 | #' 23 | #' # Conditionally format background cell colors 24 | #' format_ft_colors(ft) 25 | format_ft_colors <- function( 26 | ft, 27 | lighter_color = "#F2F0E6", 28 | darker_color = "#ccc29c", 29 | language = "English" 30 | ) { 31 | # Language arg must be "English" or "Spanish" 32 | rlang::arg_match( 33 | arg = language, 34 | values = c("English", "Spanish") 35 | ) 36 | 37 | # Color formatter function 38 | ft <- flextable::bg( 39 | ft, 40 | bg = function(x) { 41 | dplyr::case_when( 42 | is.character(x) ~ "white", 43 | x < tail(x, n = 1) ~ lighter_color, 44 | x >= tail(x, n = 1) ~ darker_color, 45 | TRUE ~ "white" 46 | ) 47 | } 48 | ) 49 | 50 | # Add an empty footer line 51 | ft <- flextable::add_footer_lines(ft, values = "") 52 | 53 | # English footnote 54 | # Add the footnote content, with the backgrounds highlighted 55 | if (language == "English") { 56 | ft <- flextable::compose( 57 | ft, 58 | i = 1, 59 | j = 1, 60 | part = "footer", 61 | value = flextable::as_paragraph( 62 | "Values \U2265 project average have ", 63 | flextable::as_highlight( 64 | "darker backgrounds. \n", 65 | darker_color 66 | ), 67 | "Values < project average have ", 68 | flextable::as_highlight( 69 | "lighter backgrounds. ", 70 | lighter_color 71 | ) 72 | ) 73 | ) 74 | } 75 | 76 | # Spanish footnote 77 | # Add the footnote content, with the backgrounds highlighted 78 | if (language == "Spanish") { 79 | ft <- flextable::compose( 80 | ft, 81 | i = 1, 82 | j = 1, 83 | part = "footer", 84 | value = flextable::as_paragraph( 85 | "Valores \U2265 promedio de proyectos tienen ", 86 | flextable::as_highlight( 87 | "fondos m\u00e1s oscuros. \n", 88 | darker_color 89 | ), 90 | "Valores < promedio de proyectos tienen ", 91 | flextable::as_highlight( 92 | "fondos m\u00e1s claros ", 93 | lighter_color 94 | ) 95 | ) 96 | ) 97 | } 98 | return(ft) 99 | } 100 | 101 | #' Style a flextable 102 | #' 103 | #' @param ft Flextable object. 104 | #' @param header_font Font of header text. Defaults to `"Lato"`. 105 | #' @param body_font Font of body text. Defaults to `"Poppins"`. 106 | #' @param header_color Background color of header cells. Defaults to WaSHI 107 | #' green. 108 | #' @param header_text_color Color of header text. Defaults to white. 109 | #' @param border_color Color of border lines. Defaults to WaSHI gray. 110 | #' 111 | #' @returns Styled flextable object. 112 | #' 113 | #' @export 114 | #' 115 | #' @examples 116 | #' # Read in wrangled example table data 117 | #' tables_path <- soils_example("tables.RDS") 118 | #' tables <- readRDS(tables_path) 119 | #' 120 | #' # Make the table 121 | #' ft <- flextable::flextable(tables$biological) 122 | #' ft 123 | #' 124 | #' # Style the table 125 | #' style_ft(ft) 126 | style_ft <- function( 127 | ft, 128 | header_font = "Lato", 129 | body_font = "Poppins", 130 | header_color = "#023B2C", 131 | header_text_color = "white", 132 | border_color = "#3E3D3D" 133 | ) { 134 | flextable::set_flextable_defaults( 135 | font.family = body_font, 136 | font.size = 10 137 | ) 138 | 139 | header_cell <- officer::fp_cell( 140 | background.color = header_color 141 | ) 142 | header_text <- officer::fp_text( 143 | font.family = header_font, 144 | font.size = 11, 145 | bold = TRUE, 146 | color = header_text_color 147 | ) 148 | 149 | ft <- flextable::style( 150 | ft, 151 | pr_t = header_text, 152 | pr_c = header_cell, 153 | part = "header" 154 | ) |> 155 | flextable::bold(j = 1, bold = TRUE, part = "body") |> 156 | flextable::hline( 157 | border = officer::fp_border( 158 | color = border_color 159 | ), 160 | part = "body" 161 | ) |> 162 | flextable::align(align = "center", part = "header") |> 163 | flextable::line_spacing(space = 1.3, part = "all") 164 | 165 | return(ft) 166 | } 167 | 168 | #' Add bottom border to specific columns in flextable 169 | #' 170 | #' Use when columns with the same units are merged together to add a bottom 171 | #' border to make it more obvious those columns share units. 172 | #' 173 | #' @param ft flextable object 174 | #' @inheritParams make_ft 175 | #' 176 | #' @returns Flextable object with bottom borders added. 177 | #' @export 178 | #' 179 | #' @examples 180 | #' # Read in wrangled table data 181 | #' headers_path <- soils_example("headers.RDS") 182 | #' headers <- readRDS(headers_path) 183 | #' 184 | #' tables_path <- soils_example("tables.RDS") 185 | #' tables <- readRDS(tables_path) 186 | #' 187 | #' # Input dataframes 188 | #' headers$chemical 189 | #' 190 | #' tables$chemical 191 | #' 192 | #' # Make the flextable 193 | #' make_ft( 194 | #' table = tables$chemical, 195 | #' header = headers$chemical 196 | #' ) |> 197 | #' # Style the flextable 198 | #' style_ft() |> 199 | #' # Add the white line under the columns with the same units 200 | #' unit_hline(header = headers$chemical) 201 | #' 202 | #' # Example without `unit_hline()` 203 | #' make_ft( 204 | #' table = tables$chemical, 205 | #' header = headers$chemical 206 | #' ) |> 207 | #' # Style the flextable 208 | #' style_ft() 209 | unit_hline <- function(ft, header) { 210 | # Get row index of first duplicated unit for unit_hline 211 | dupe_row <- which(duplicated(header$unit)) |> utils::head(1) 212 | ft |> 213 | flextable::merge_h(part = "header") |> 214 | flextable::hline( 215 | i = 1, 216 | j = dupe_row, 217 | part = "header", 218 | border = officer::fp_border(color = "white") 219 | ) 220 | } 221 | 222 | #' Make a flextable with column names from another dataframe 223 | #' 224 | #' @param table A dataframe with the contents of the desired flextable output. 225 | #' @param header Another dataframe with three columns: 226 | #' * First column contains what the top header row should be. In our template, 227 | #' this is the abbreviation of the measurement (i.e. `Organic Matter`). 228 | #' * Second column, called `"key"`, contains the join key. In our template, 229 | #' this is the same as the first column. 230 | #' * Third column contains the second header row. In our template, this is 231 | #' the unit (i.e. `%`). 232 | #' 233 | #' @export 234 | #' @returns Formatted flextable object. 235 | #' 236 | #' @examples 237 | #' # Read in wrangled table data 238 | #' headers_path <- soils_example("headers.RDS") 239 | #' headers <- readRDS(headers_path) 240 | #' 241 | #' tables_path <- soils_example("tables.RDS") 242 | #' tables <- readRDS(tables_path) 243 | #' 244 | #' # Input dataframes 245 | #' headers$chemical 246 | #' 247 | #' tables$chemical 248 | #' 249 | #' # Make the flextable 250 | #' make_ft( 251 | #' table = tables$chemical, 252 | #' header = headers$chemical 253 | #' ) |> 254 | #' # Style the flextable 255 | #' style_ft() |> 256 | #' # Add the white line under the columns with the same units 257 | #' unit_hline(header = headers$chemical) 258 | #' 259 | make_ft <- function(table, header) { 260 | # Get row index of first duplicated unit for unit_hline 261 | dupe_row <- which(duplicated(header$unit)) |> 262 | utils::head(1) 263 | 264 | table |> 265 | flextable::flextable() |> 266 | flextable::set_header_df( 267 | mapping = header, 268 | key = "key" 269 | ) 270 | } 271 | -------------------------------------------------------------------------------- /vignettes/quarto.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Quarto" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Quarto} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | ```{r, include = FALSE} 11 | knitr::opts_chunk$set( 12 | collapse = TRUE, 13 | comment = "#>" 14 | ) 15 | ``` 16 | 17 | If you're new to Quarto, first check out the [**Hello, Quarto 18 | tutorial**](https://quarto.org/docs/get-started/hello/rstudio.html) and explore 19 | the documentation. 20 | 21 | This primer is not a comprehensive introduction to Quarto. Instead, it provides 22 | a brief reference for workflows and features used in {soils}. 23 | 24 | # File paths 25 | 26 | `soils::create_soils(path = "soils-demo")` creates an RStudio Project called 27 | "soils-demo" with the template Quarto (`.qmd`) files, example data, R script, 28 | images, style sheets, and the `.Rproj` file that designates the directory as an 29 | RStudio Project. All template files use **relative paths** instead of absolute 30 | paths to ensure the file paths work on anyone's computer. 31 | 32 | ## Absolute vs relative paths 33 | 34 | ❌ **Absolute paths** start with the root directory and provide the full path to 35 | a specific file or folder 36 | (`C:/Users/jryan/Documents/R/projects/soils-demo/data/washi-data.csv`). This 37 | path **will not work** on anyone's computer unless the operating system, user, 38 | directory structure, and folder names match exactly. 39 | 40 | ✅ **Relative paths** are *relative* to the working directory, or the project's 41 | home (`data/washi-data.csv`). When working in a RStudio project, the default 42 | working directory is always the root project directory (where the `.Rproj` file 43 | is). This path **will work** on anyone's computer with this project directory. 44 | 45 | ## {here} package 46 | 47 | When a Quarto file renders, its default current working directory is where the 48 | `.qmd` file lives. To make code more robust, the 49 | [{here}](https://here.r-lib.org/) package builds *relative* file paths and takes 50 | care of the backslashes or forward slashes so the path will work no matter the 51 | operating system. 52 | 53 | For example, in our new {soils} project, `01_producer-report.qmd` imports data 54 | using `read.csv(here::here("data/washi-data.csv"))`. 55 | 56 | # Parameterized reporting 57 | 58 | {soils} uses Quarto to help you generate **parameterized** reports for each 59 | participant in your survey from the same template file. 60 | 61 | Parameterized reports are like complex functions where the **function** is the 62 | `.qmd` template, the **input** are the parameters, and the **output** are the 63 | reports. 64 | 65 | ![](../man/figures/parameterized-reports.png){fig-alt="A diagram showing parameters/input with an arrow pointing to a Quarto file as the template/function. Many arrows lead from the Quarto file to the reports/output as five different reports representing five different years."} 66 | 67 | To learn more about parameterized reporting, see the materials for [Jadey Ryan's 68 | 20-minute 69 | presentation](https://jadeyryan.com/talks/2023-09-25_posit_parameterized-quarto/), 70 | follow along with her [2-hour code-along 71 | workshop](https://jadeyryan.quarto.pub/rladies-dc-quarto-params/), or read the 72 | [Quarto parameters 73 | documentation](https://quarto.org/docs/computations/parameters.html). 74 | 75 | # Quarto specific features 76 | 77 | {soils} uses several intermediate to advanced Quarto features, listed below with 78 | references for further reading. 79 | 80 | ## Shortcodes 81 | 82 | Shortcodes are special markdown directives that generate various types of 83 | content. The markdown syntax uses the shortcode name and attributes inside angle 84 | brackets that are nested inside double curly braces `{{< shortcode >}}`. Read 85 | more in the [Shortcodes 86 | article](https://quarto.org/docs/extensions/shortcodes.html). 87 | 88 | ### Pagebreak 89 | 90 | `pagebreak` inserts native page breaks into a document regardless of the report 91 | format (e.g., HTML, MS Word). Read more in the [Pagebreaks 92 | article](https://quarto.org/docs/authoring/markdown-basics.html#page-breaks). 93 | 94 | ``` r 95 | {{< pagebreak >}} 96 | ``` 97 | 98 | ### Include 99 | 100 | `include` embeds content from a separate `.qmd` file into the main report. This 101 | shortens the number of lines in the main `.qmd` file and makes the markdown and 102 | code of the project more modular. Read more in the [Includes 103 | article](https://quarto.org/docs/authoring/includes.html). 104 | 105 | Examples found in `01_producer-report.qmd` are shown below. 106 | 107 | ``` r 108 | {{< include 03_project-summary.qmd >}} 109 | 110 | {{< include 04_soil-health-background.qmd >}} 111 | ``` 112 | 113 | ## `knitr::knit_child()` 114 | 115 | The include shortcode is limited and cannot generate dynamic sections from an 116 | "included" Quarto file. {soils} uses the `knitr::knit_child()` function as a 117 | workaround, thanks to [Quishi Yan's blog 118 | post](https://www.qiushiyan.dev/posts/dynamic-rmd-quarto/). 119 | 120 | For each measurement group results section, `02_section-template.qmd` is used as 121 | a template to generate each section's header, table, plot, and page break. 122 | 123 | The below code is in the `create-measurement-group-sections` code chunk of 124 | `01_producer-report.qmd`. 125 | 126 | ```{r eval=FALSE} 127 | #| output: asis 128 | 129 | sections <- purrr::map_chr(measurement_groups, \(group) { # <1> 130 | knitr::knit_child( 131 | input = "02_section-template.qmd", 132 | envir = rlang::env(), 133 | quiet = TRUE 134 | ) 135 | }) 136 | 137 | cat(sections, sep = "\n") # <2> 138 | ``` 139 | 140 | 1. `purrr::map_chr()` loops over each measurement group to generate its section 141 | as a child document. 142 | 2. With the chunk option `#| output: asis` and the `cat(sections, sep = "\n")` 143 | line, the child documents are embedded within the main producer report. 144 | 145 | ## Divs and spans 146 | 147 | Add classes and attributes to regions of content with divs and spans. 148 | 149 | ### Divs 150 | 151 | Divs start and end with a fence containing *at least* three consecutive colons 152 | (`:::`). The div should be separated by blank lines from preceding and following 153 | blocks. 154 | 155 | Divs may or may not use curly braces `{}` around the class and attributes. In 156 | the below example, `columns` is a standalone class, while `.column width="50%"` 157 | is a class with an attribute. 158 | 159 | Divs may also be nested, as shown below. Optionally, more than three consecutive 160 | colons to distinguish nested divs from their parents. 161 | 162 | ``` markdown 163 | :::: columns 164 | 165 | ::: {.column width="50%"} 166 | Left column 167 | ::: 168 | 169 | ::: {.column width="50%"} 170 | Right column 171 | ::: 172 | 173 | :::: 174 | ``` 175 | 176 | ### Spans 177 | 178 | Bracketed text immediately followed by a class or attributes in curly braces 179 | `{}` will be treated as a span. 180 | 181 | ``` 182 | [Purple]{style="color:purple;font-weight: bold;font-size: x-large;"} is my favorite color. 183 | ``` 184 | 185 | is rendered as: 186 | [Purple]{style="color:purple;font-weight: bold;font-size: x-large;"} is my 187 | favorite color. 188 | 189 | Read more in the [Divs and Spans 190 | documentation](https://quarto.org/docs/authoring/markdown-basics.html#divs-and-spans). 191 | 192 | ## Conditional Content 193 | 194 | Conditional content classes and attributes control whether content *is* or *is 195 | not* displayed in a given format. For example, to control visibility for HTML 196 | formats, use a div with the `.content-visible` class and the 197 | `when-format="html"` OR `unless-format="html"` attribute. Read more in the 198 | [Conditional Content 199 | article](https://quarto.org/docs/authoring/conditional.html). 200 | 201 | ``` markdown 202 | ::: {.content-visible when-format="html"} 203 | This interactive content will ONLY appear in HTML reports. 204 | ::: 205 | 206 | ::: {.content-visible unless-format="html"} 207 | This static content will appear in all reports EXCEPT in HTML reports. 208 | ::: 209 | ``` 210 | 211 | ## Tabsets 212 | 213 | Tabsets work only in HTML documents and are created with the `::: panel-tabset` 214 | div. Each top-level heading within the div creates a new tab. Read more in the 215 | [Tabsets 216 | article](https://quarto.org/docs/output-formats/html-basics.html#tabsets). 217 | 218 | The below example shows how `04_soil-health-background.qmd` uses **include** 219 | shortcodes, **nested divs**, **conditional content**, and a **tabset** to 220 | include a tabset *only* for HTML reports. 221 | 222 | ``` markdown 223 | ::: {.content-visible when-format="html"} 224 | :::: panel-tabset 225 | {{< include 05_physical-measurements.qmd >}} 226 | 227 | {{< include 06_biological-measurements.qmd >}} 228 | 229 | {{< include 07_chemical-measurements.qmd >}} 230 | :::: 231 | ::: 232 | 233 | ::: {.content-visible unless-format="html"} 234 | {{< include 05_physical-measurements.qmd >}} 235 | 236 | {{< include 06_biological-measurements.qmd >}} 237 | 238 | {{< include 07_chemical-measurements.qmd >}} 239 | ::: 240 | ``` 241 | -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | # soils ![](man/figures/logo.png){align="right" height="138"} 6 | 7 | 8 | 9 | [![Project Status: Active -- The project has reached a stable, usable state and 10 | is being actively 11 | developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) 12 | 13 | [![CRAN 14 | status](https://www.r-pkg.org/badges/version/soils)](https://CRAN.R-project.org/package=soils) 15 | [![:name status 16 | badge](https://wa-department-of-agriculture.r-universe.dev/badges/:name)](https://wa-department-of-agriculture.r-universe.dev/) 17 | [![soils status 18 | badge](https://wa-department-of-agriculture.r-universe.dev/badges/soils)](https://wa-department-of-agriculture.r-universe.dev/soils) 19 | [![R-CMD-check](https://github.com/WA-Department-of-Agriculture/soils/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/WA-Department-of-Agriculture/soils/actions/workflows/R-CMD-check.yaml) 20 | 21 | 22 | 23 | ```{r setup, include=FALSE} 24 | knitr::opts_chunk$set( 25 | fig.align = "left", 26 | dpi = 300 27 | ) 28 | ``` 29 | 30 | 📢 **Announcing Dirt Data Reports: a no-code soil health reporting tool built on 31 | {soils} using Shiny** 32 | 33 | 👉 Try it [here](https://wsda.shinyapps.io/dirt-data-reports/) if you don't need 34 | full customization or prefer not to code. 35 | 36 | 📖 Read more about it in this [blog 37 | post](https://washingtonsoilhealthinitiative.com/2025/09/dirt-data-reports/). 38 | 39 | # Overview 40 | 41 | {soils} is an R package for all your soil health data visualization and 42 | reporting needs. {soils} provides an RStudio project template to generate 43 | customized, interactive soil health reports. These reports include plots and 44 | tables to show how the participant's results compare to simple averages of 45 | results from samples of the same crop, same county, and across the entire 46 | project. 47 | 48 | Any scientist leading a soil health survey can use {soils} to create custom 49 | reports for all participants. Democratize your data by giving back to the 50 | farmers and land managers who contributed soil samples to your soil sampling 51 | project. Use these reports to empower each participant to explore and better 52 | understand their data. 53 | 54 | The [Washington State Department of 55 | Agriculture](https://agr.wa.gov/departments/land-and-water/natural-resources/soil-health) 56 | and [Washington State University](https://soilhealth.wsu.edu/) developed {soils} 57 | as part of the [Washington Soil Health 58 | Initiative](https://washingtonsoilhealthinitiative.com/). Learn more about 59 | {soils} in this [blog 60 | post](https://washingtonsoilhealthinitiative.com/2024/03/soils-an-r-package-for-soil-health-reporting/) 61 | or this [webinar](https://youtu.be/_8m7fTjSEOk?si=ikrCASdchiB6rDC2). 62 | 63 | # Requirements 64 | 65 | The report template uses [Quarto](https://quarto.org/docs/get-started/), which 66 | is the [next-generation](https://quarto.org/docs/faq/rmarkdown.html) version of 67 | [R Markdown](https://quarto.org/docs/faq/rmarkdown.html). 68 | 69 | We assume you're using [RStudio 70 | v2022.07](https://dailies.rstudio.com/version/2022.07.2+576.pro12/) or later for 71 | editing and previewing Quarto documents. We **strongly recommend** you use the 72 | [latest release of RStudio](https://posit.co/download/rstudio-desktop/) for 73 | support of all Quarto features. You can also download and install the [latest 74 | version of Quarto](https://quarto.org/docs/get-started/) independently from 75 | RStudio. 76 | 77 | To render Microsoft Word (MS Word) documents, you must have MS Word installed 78 | and activated. 79 | 80 | **If you're new to Quarto and Markdown formatting syntax, first take a look at 81 | the Primers on 82 | [Quarto](https://wa-department-of-agriculture.github.io/soils/articles/quarto.html) 83 | and 84 | [Markdown](https://wa-department-of-agriculture.github.io/soils/articles/markdown.html) 85 | to learn how they're used in {soils} and get familiar with their features.** 86 | 87 | # Installation 88 | 89 | Install the development version of {soils} from our 90 | [r-universe](https://wa-department-of-agriculture.r-universe.dev/) with: 91 | 92 | ```{r install-r-universe, eval=FALSE} 93 | install.packages( 94 | "soils", 95 | repos = c("https://wa-department-of-agriculture.r-universe.dev") 96 | ) 97 | ``` 98 | 99 | Or install from GitHub with [{pak}](https://pak.r-lib.org/index.html): 100 | 101 | ```{r pak-install, eval=FALSE} 102 | # Uncomment the below line if {pak} is not installed. 103 | # install.packages("pak") 104 | pak::pkg_install("WA-Department-of-Agriculture/soils") 105 | ``` 106 | 107 | Load the example datasets and functions with: 108 | 109 | ```{r load-soils, eval=FALSE} 110 | library(soils) 111 | ``` 112 | 113 | # Usage 114 | 115 | {soils} was developed to work 'out of the box' so you can immediately install 116 | and render an example report. However, you will need to customize and edit 117 | content to fit your project. 118 | 119 | Our recommended workflow is to **1)** create a new {soils} project, **2)** try 120 | to render the example reports to make sure everything works on your system, and 121 | **3)** customize the template files to use your own data, content, and styling. 122 | 123 | We provide a series of [Primers and 124 | Tutorials](https://wa-department-of-agriculture.github.io/soils/articles/index.html) 125 | to prepare and guide you through this workflow. See below for short demo videos 126 | and links to the relevant tutorials. 127 | 128 | ## 1. Create a new {soils} project 129 | 130 | Follow along in the [**Create a {soils} 131 | project**](https://wa-department-of-agriculture.github.io/soils/articles/project.html) 132 | tutorial. Choose between two report templates: **English** or **Spanish**. 133 | 134 | [create-soils.webm](https://github.com/WA-Department-of-Agriculture/soils/assets/95007373/12a01cf7-0efc-4948-b41e-a826dd86e6f6) 135 | 136 | ## 2. Render the example reports 137 | 138 | Follow along in the [**Render the example 139 | reports**](https://wa-department-of-agriculture.github.io/soils/articles/render-example.html) 140 | tutorial. 141 | 142 | See the [**rendered example 143 | reports**](https://wa-department-of-agriculture.github.io/soils/articles/examples.html). 144 | 145 | ### HTML 146 | 147 | [render-html.webm](https://github.com/WA-Department-of-Agriculture/soils/assets/95007373/a1f680a0-bed4-495a-aae7-ba85a9fa22e3) 148 | 149 | ### MS Word 150 | 151 | [render-docx.webm](https://github.com/WA-Department-of-Agriculture/soils/assets/95007373/a617fee6-a53b-4772-ac3b-bf8d48f8fc5b) 152 | 153 | ## 3. Create reports with your own data 154 | 155 | To use your own data, customize the reports for your project, and render all 156 | reports, follow along with these tutorials: 157 | 158 | - [**Import 159 | data**](https://wa-department-of-agriculture.github.io/soils/articles/data.html) 160 | 161 | - [**Customize & 162 | write**](https://wa-department-of-agriculture.github.io/soils/articles/customize.html) 163 | 164 | - [**Render 165 | reports**](https://wa-department-of-agriculture.github.io/soils/articles/render.html) 166 | 167 | [render-reports.webm](https://github.com/WA-Department-of-Agriculture/soils/assets/95007373/b796f674-ed90-4d57-bed3-85b58c399c8f) 168 | 169 | ## Troubleshooting 170 | 171 | As you edit the content, errors are bound to occur. Read [**tips and workflows 172 | for 173 | troubleshooting**](https://wa-department-of-agriculture.github.io/soils/articles/troubleshoot.html) 174 | 175 | # Acknowledgement and citation 176 | 177 | The below acknowledgement is automatically embedded in each report: 178 | 179 | ```{r acknowledgement, echo = FALSE, results='asis'} 180 | acknowledgement <- knitr::knit_child( 181 | here::here("inst/templates/english/09_acknowledgement.qmd"), 182 | quiet = TRUE 183 | ) 184 | 185 | cat(">", acknowledgement) 186 | ``` 187 | 188 | ```{r citation-header, echo=FALSE, results='asis'} 189 | citation <- citation("soils") 190 | 191 | header <- format(citation, style = "citation")[[1]] 192 | text <- format(citation, style = "textVersion") 193 | 194 | cat(header) 195 | ``` 196 | 197 | ```{r citation-text, echo=FALSE, results='asis'} 198 | cat(">", text) 199 | ``` 200 | 201 | ## Credits 202 | 203 | {soils} adapts from existing R project templating resources and packages: 204 | 205 | - [RStudio Project 206 | Templates](https://rstudio.github.io/rstudio-extensions/rstudio_project_templates.html) 207 | - [{ratlas}](https://github.com/atlas-aai/ratlas) 208 | - [{quartotemplate}](https://github.com/Pecners/quartotemplate) 209 | - [{golem}](https://github.com/ThinkR-open/golem/) 210 | 211 | Text and figures were adapted from [WSU Extension publication #FS378E Soil 212 | Health in Washington 213 | Vineyards](https://pubs.extension.wsu.edu/soil-health-in-washington-vineyards). 214 | 215 | Report text and images were translated by Erica Tello, Eber Rivera, and Kate 216 | Smith with WSU Food Systems and Skagit County Extension as part of the USDA NRCS 217 | Innovation in Conservation program, led by Viva Farms (grant number 218 | NR22-13G004). 219 | 220 | -------------------------------------------------------------------------------- /pkgdown/index.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | # soils ![](../man/figures/logo.png){align="right" height="138"} 6 | 7 | 8 | 9 | [![Project Status: WIP -- Initial development is in progress, but there has not 10 | yet been a stable, usable release suitable for the 11 | public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip) 12 | 13 | [![CRAN 14 | status](https://www.r-pkg.org/badges/version/soils)](https://CRAN.R-project.org/package=soils) 15 | [![:name status 16 | badge](https://wa-department-of-agriculture.r-universe.dev/badges/:name)](https://wa-department-of-agriculture.r-universe.dev/) 17 | [![soils status 18 | badge](https://wa-department-of-agriculture.r-universe.dev/badges/soils)](https://wa-department-of-agriculture.r-universe.dev/soils) 19 | [![R-CMD-check](https://github.com/WA-Department-of-Agriculture/soils/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/WA-Department-of-Agriculture/soils/actions/workflows/R-CMD-check.yaml) 20 | 21 | 22 | 23 | ```{r setup, include=FALSE} 24 | knitr::opts_chunk$set( 25 | fig.align = "left", 26 | dpi = 300 27 | ) 28 | ``` 29 | 30 | 📢 **Announcing Dirt Data Reports: a no-code soil health reporting tool built on 31 | {soils} using Shiny** 32 | 33 | 👉 Try it [here](https://wsda.shinyapps.io/dirt-data-reports/) if you don't need 34 | full customization or prefer not to code. 35 | 36 | 📖 Read more about it in this [blog 37 | post](https://washingtonsoilhealthinitiative.com/2025/09/dirt-data-reports/). 38 | 39 | # Overview 40 | 41 | {soils} is an R package for all your soil health data visualization and 42 | reporting needs. {soils} provides an RStudio project template to generate 43 | customized, interactive soil health reports. These reports include plots and 44 | tables to show how the participant's results compare to simple averages of 45 | results from samples of the same crop, same county, and across the entire 46 | project. 47 | 48 | Any scientist leading a soil health survey can use {soils} to create custom 49 | reports for all participants. Democratize your data by giving back to the 50 | farmers and land managers who contributed soil samples to your soil sampling 51 | project. Use these reports to empower each participant to explore and better 52 | understand their data. 53 | 54 | The [Washington State Department of 55 | Agriculture](https://agr.wa.gov/departments/land-and-water/natural-resources/soil-health) 56 | and [Washington State University](https://soilhealth.wsu.edu/) developed {soils} 57 | as part of the [Washington Soil Health 58 | Initiative](https://washingtonsoilhealthinitiative.com/). Learn more about 59 | {soils} in this [blog 60 | post](https://washingtonsoilhealthinitiative.com/2024/03/soils-an-r-package-for-soil-health-reporting/) 61 | or this [webinar](https://youtu.be/_8m7fTjSEOk?si=ikrCASdchiB6rDC2). 62 | 63 | # Requirements 64 | 65 | The report template uses [Quarto](https://quarto.org/docs/get-started/), which 66 | is the [next-generation](https://quarto.org/docs/faq/rmarkdown.html) version of 67 | [R Markdown](https://quarto.org/docs/faq/rmarkdown.html). 68 | 69 | We assume you're using [RStudio 70 | v2022.07](https://dailies.rstudio.com/version/2022.07.2+576.pro12/) or later for 71 | editing and previewing Quarto documents. We **strongly recommend** you use the 72 | [latest release of RStudio](https://posit.co/download/rstudio-desktop/) for 73 | support of all Quarto features. You can also download and install the [latest 74 | version of Quarto](https://quarto.org/docs/get-started/) independently from 75 | RStudio. 76 | 77 | To render Microsoft Word (MS Word) documents, you must have MS Word installed 78 | and activated. 79 | 80 | **If you're new to Quarto and Markdown formatting syntax, first take a look at 81 | the Primers on 82 | [Quarto](https://wa-department-of-agriculture.github.io/soils/articles/quarto.html) 83 | and 84 | [Markdown](https://wa-department-of-agriculture.github.io/soils/articles/markdown.html) 85 | to learn how they're used in {soils} and get familiar with their features.** 86 | 87 | # Installation 88 | 89 | Install the development version of {soils} from our 90 | [r-universe](https://wa-department-of-agriculture.r-universe.dev/) with: 91 | 92 | ```{r install-r-universe, eval=FALSE} 93 | install.packages( 94 | "soils", 95 | repos = c("https://wa-department-of-agriculture.r-universe.dev") 96 | ) 97 | ``` 98 | 99 | Or install from GitHub with [{pak}](https://pak.r-lib.org/index.html): 100 | 101 | ```{r pak-install, eval=FALSE} 102 | # Uncomment the below line if {pak} is not installed. 103 | # install.packages("pak") 104 | pak::pkg_install("WA-Department-of-Agriculture/soils") 105 | ``` 106 | 107 | Load the example datasets and functions with: 108 | 109 | ```{r load-soils, eval=FALSE} 110 | library(soils) 111 | ``` 112 | 113 | # Usage 114 | 115 | {soils} was developed to work 'out of the box' so you can immediately install 116 | and render an example report. However, you will need to customize and edit 117 | content to fit your project. 118 | 119 | Our recommended workflow is to **1)** create a new {soils} project, **2)** try 120 | to render the example reports to make sure everything works on your system, and 121 | **3)** customize the template files to use your own data, content, and styling. 122 | 123 | We provide a series of [Primers and 124 | Tutorials](https://wa-department-of-agriculture.github.io/soils/articles/index.html) 125 | to prepare and guide you through this workflow. See below for short demo videos 126 | and links to the relevant tutorials. 127 | 128 | ## 1. Create a new {soils} project 129 | 130 | Follow along in the [**Create a {soils} 131 | project**](https://wa-department-of-agriculture.github.io/soils/articles/project.html) 132 | tutorial. Choose between two report templates: **English** or **Spanish**. 133 | 134 | 137 | 138 | ## 2. Render the example reports 139 | 140 | Follow along in the [**Render the example 141 | reports**](https://wa-department-of-agriculture.github.io/soils/articles/render-example.html) 142 | tutorial. 143 | 144 | See the [**rendered example 145 | reports**](https://wa-department-of-agriculture.github.io/soils/articles/examples.html). 146 | 147 | ### HTML 148 | 149 | 152 | 153 | ### MS Word 154 | 155 | 158 | 159 | ## 3. Create reports with your own data 160 | 161 | To use your own data, customize the reports for your project, and render all 162 | reports, follow along with these tutorials: 163 | 164 | - [**Import 165 | data**](https://wa-department-of-agriculture.github.io/soils/articles/data.html) 166 | 167 | - [**Customize & 168 | write**](https://wa-department-of-agriculture.github.io/soils/articles/customize.html) 169 | 170 | - [**Render 171 | reports**](https://wa-department-of-agriculture.github.io/soils/articles/render.html) 172 | 173 | 176 | 177 | ## Troubleshooting 178 | 179 | As you edit the content, errors are bound to occur. Read [**tips and workflows 180 | for 181 | troubleshooting**](https://wa-department-of-agriculture.github.io/soils/articles/troubleshoot.html) 182 | 183 | # Acknowledgement and citation 184 | 185 | The below acknowledgement is automatically embedded in each report: 186 | 187 | ```{r acknowledgement, echo = FALSE, results='asis'} 188 | acknowledgement <- knitr::knit_child( 189 | here::here("inst/templates/english/09_acknowledgement.qmd"), 190 | quiet = TRUE 191 | ) 192 | 193 | cat(">", acknowledgement) 194 | ``` 195 | 196 | ```{r citation-header, echo=FALSE, results='asis'} 197 | citation <- citation("soils") 198 | 199 | header <- format(citation, style = "citation")[[1]] 200 | text <- format(citation, style = "textVersion") 201 | 202 | cat(header) 203 | ``` 204 | 205 | ```{r citation-text, echo=FALSE, results='asis'} 206 | cat(">", text) 207 | ``` 208 | 209 | ## Credits 210 | 211 | {soils} adapts from existing R project templating resources and packages: 212 | 213 | - [RStudio Project 214 | Templates](https://rstudio.github.io/rstudio-extensions/rstudio_project_templates.html) 215 | - [{ratlas}](https://github.com/atlas-aai/ratlas) 216 | - [{quartotemplate}](https://github.com/Pecners/quartotemplate) 217 | - [{golem}](https://github.com/ThinkR-open/golem/) 218 | 219 | Text and figures were adapted from [WSU Extension publication #FS378E Soil 220 | Health in Washington 221 | Vineyards](https://pubs.extension.wsu.edu/soil-health-in-washington-vineyards). 222 | 223 | Report text and images were translated by Erica Tello, Eber Rivera, and Kate 224 | Smith with WSU Food Systems and Skagit County Extension as part of the USDA NRCS 225 | Innovation in Conservation program, led by Viva Farms (grant number 226 | NR22-13G004). 227 | 228 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # soils 3 | 4 | 5 | 6 | [![Project Status: Active – The project has reached a stable, usable 7 | state and is being actively 8 | developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) 9 | 10 | [![CRAN 11 | status](https://www.r-pkg.org/badges/version/soils)](https://CRAN.R-project.org/package=soils) 12 | [![:name status 13 | badge](https://wa-department-of-agriculture.r-universe.dev/badges/:name)](https://wa-department-of-agriculture.r-universe.dev/) 14 | [![soils status 15 | badge](https://wa-department-of-agriculture.r-universe.dev/badges/soils)](https://wa-department-of-agriculture.r-universe.dev/soils) 16 | [![R-CMD-check](https://github.com/WA-Department-of-Agriculture/soils/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/WA-Department-of-Agriculture/soils/actions/workflows/R-CMD-check.yaml) 17 | 18 | 19 | 20 | 📢 **Announcing Dirt Data Reports: a no-code soil health reporting tool 21 | built on {soils} using Shiny** 22 | 23 | 👉 Try it [here](https://wsda.shinyapps.io/dirt-data-reports/) if you 24 | don’t need full customization or prefer not to code. 25 | 26 | 📖 Read more about it in this [blog 27 | post](https://washingtonsoilhealthinitiative.com/2025/09/dirt-data-reports/). 28 | 29 | # Overview 30 | 31 | {soils} is an R package for all your soil health data visualization and 32 | reporting needs. {soils} provides an RStudio project template to 33 | generate customized, interactive soil health reports. These reports 34 | include plots and tables to show how the participant’s results compare 35 | to simple averages of results from samples of the same crop, same 36 | county, and across the entire project. 37 | 38 | Any scientist leading a soil health survey can use {soils} to create 39 | custom reports for all participants. Democratize your data by giving 40 | back to the farmers and land managers who contributed soil samples to 41 | your soil sampling project. Use these reports to empower each 42 | participant to explore and better understand their data. 43 | 44 | The [Washington State Department of 45 | Agriculture](https://agr.wa.gov/departments/land-and-water/natural-resources/soil-health) 46 | and [Washington State University](https://soilhealth.wsu.edu/) developed 47 | {soils} as part of the [Washington Soil Health 48 | Initiative](https://washingtonsoilhealthinitiative.com/). Learn more 49 | about {soils} in this [blog 50 | post](https://washingtonsoilhealthinitiative.com/2024/03/soils-an-r-package-for-soil-health-reporting/) 51 | or this [webinar](https://youtu.be/_8m7fTjSEOk?si=ikrCASdchiB6rDC2). 52 | 53 | # Requirements 54 | 55 | The report template uses [Quarto](https://quarto.org/docs/get-started/), 56 | which is the 57 | [next-generation](https://quarto.org/docs/faq/rmarkdown.html) version of 58 | [R Markdown](https://quarto.org/docs/faq/rmarkdown.html). 59 | 60 | We assume you’re using [RStudio 61 | v2022.07](https://dailies.rstudio.com/version/2022.07.2+576.pro12/) or 62 | later for editing and previewing Quarto documents. We **strongly 63 | recommend** you use the [latest release of 64 | RStudio](https://posit.co/download/rstudio-desktop/) for support of all 65 | Quarto features. You can also download and install the [latest version 66 | of Quarto](https://quarto.org/docs/get-started/) independently from 67 | RStudio. 68 | 69 | To render Microsoft Word (MS Word) documents, you must have MS Word 70 | installed and activated. 71 | 72 | **If you’re new to Quarto and Markdown formatting syntax, first take a 73 | look at the Primers on 74 | [Quarto](https://wa-department-of-agriculture.github.io/soils/articles/quarto.html) 75 | and 76 | [Markdown](https://wa-department-of-agriculture.github.io/soils/articles/markdown.html) 77 | to learn how they’re used in {soils} and get familiar with their 78 | features.** 79 | 80 | # Installation 81 | 82 | Install the development version of {soils} from our 83 | [r-universe](https://wa-department-of-agriculture.r-universe.dev/) with: 84 | 85 | ``` r 86 | install.packages( 87 | "soils", 88 | repos = c("https://wa-department-of-agriculture.r-universe.dev") 89 | ) 90 | ``` 91 | 92 | Or install from GitHub with [{pak}](https://pak.r-lib.org/index.html): 93 | 94 | ``` r 95 | # Uncomment the below line if {pak} is not installed. 96 | # install.packages("pak") 97 | pak::pkg_install("WA-Department-of-Agriculture/soils") 98 | ``` 99 | 100 | Load the example datasets and functions with: 101 | 102 | ``` r 103 | library(soils) 104 | ``` 105 | 106 | # Usage 107 | 108 | {soils} was developed to work ‘out of the box’ so you can immediately 109 | install and render an example report. However, you will need to 110 | customize and edit content to fit your project. 111 | 112 | Our recommended workflow is to **1)** create a new {soils} project, 113 | **2)** try to render the example reports to make sure everything works 114 | on your system, and **3)** customize the template files to use your own 115 | data, content, and styling. 116 | 117 | We provide a series of [Primers and 118 | Tutorials](https://wa-department-of-agriculture.github.io/soils/articles/index.html) 119 | to prepare and guide you through this workflow. See below for short demo 120 | videos and links to the relevant tutorials. 121 | 122 | ## 1. Create a new {soils} project 123 | 124 | Follow along in the [**Create a {soils} 125 | project**](https://wa-department-of-agriculture.github.io/soils/articles/project.html) 126 | tutorial. Choose between two report templates: **English** or 127 | **Spanish**. 128 | 129 | [create-soils.webm](https://github.com/WA-Department-of-Agriculture/soils/assets/95007373/12a01cf7-0efc-4948-b41e-a826dd86e6f6) 130 | 131 | ## 2. Render the example reports 132 | 133 | Follow along in the [**Render the example 134 | reports**](https://wa-department-of-agriculture.github.io/soils/articles/render-example.html) 135 | tutorial. 136 | 137 | See the [**rendered example 138 | reports**](https://wa-department-of-agriculture.github.io/soils/articles/examples.html). 139 | 140 | ### HTML 141 | 142 | [render-html.webm](https://github.com/WA-Department-of-Agriculture/soils/assets/95007373/a1f680a0-bed4-495a-aae7-ba85a9fa22e3) 143 | 144 | ### MS Word 145 | 146 | [render-docx.webm](https://github.com/WA-Department-of-Agriculture/soils/assets/95007373/a617fee6-a53b-4772-ac3b-bf8d48f8fc5b) 147 | 148 | ## 3. Create reports with your own data 149 | 150 | To use your own data, customize the reports for your project, and render 151 | all reports, follow along with these tutorials: 152 | 153 | - [**Import 154 | data**](https://wa-department-of-agriculture.github.io/soils/articles/data.html) 155 | 156 | - [**Customize & 157 | write**](https://wa-department-of-agriculture.github.io/soils/articles/customize.html) 158 | 159 | - [**Render 160 | reports**](https://wa-department-of-agriculture.github.io/soils/articles/render.html) 161 | 162 | [render-reports.webm](https://github.com/WA-Department-of-Agriculture/soils/assets/95007373/b796f674-ed90-4d57-bed3-85b58c399c8f) 163 | 164 | ## Troubleshooting 165 | 166 | As you edit the content, errors are bound to occur. Read [**tips and 167 | workflows for 168 | troubleshooting**](https://wa-department-of-agriculture.github.io/soils/articles/troubleshoot.html) 169 | 170 | # Acknowledgement and citation 171 | 172 | The below acknowledgement is automatically embedded in each report: 173 | 174 | > This report was generated using the [{soils} R 175 | > package](https://wa-department-of-agriculture.github.io/soils/). 176 | > {soils} was developed by the Washington State Department of 177 | > Agriculture and Washington State University, as part of the Washington 178 | > Soil Health Initiative. Text and figures were adapted from [WSU 179 | > Extension publication \#FS378E Soil Health in Washington 180 | > Vineyards](https://pubs.extension.wsu.edu/soil-health-in-washington-vineyards). 181 | > Learn more about {soils} in this [blog 182 | > post](https://washingtonsoilhealthinitiative.com/2024/03/soils-an-r-package-for-soil-health-reporting/) 183 | > or this [webinar](https://youtu.be/_8m7fTjSEOk?si=ikrCASdchiB6rDC2). 184 | 185 | To cite {soils} in publications, please use: 186 | 187 | > Ryan JN, McIlquham M, Sarpong KA, Michel LM, Potter TS, Griffin LaHue 188 | > D, Gelardi DL. 2024. Visualize and Report Soil Health Data with 189 | > {soils}. Washington Soil Health Initiative. 190 | > 191 | 192 | ## Credits 193 | 194 | {soils} adapts from existing R project templating resources and 195 | packages: 196 | 197 | - [RStudio Project 198 | Templates](https://rstudio.github.io/rstudio-extensions/rstudio_project_templates.html) 199 | - [{ratlas}](https://github.com/atlas-aai/ratlas) 200 | - [{quartotemplate}](https://github.com/Pecners/quartotemplate) 201 | - [{golem}](https://github.com/ThinkR-open/golem/) 202 | 203 | Text and figures were adapted from [WSU Extension publication \#FS378E 204 | Soil Health in Washington 205 | Vineyards](https://pubs.extension.wsu.edu/soil-health-in-washington-vineyards). 206 | 207 | Report text and images were translated by Erica Tello, Eber Rivera, and 208 | Kate Smith with WSU Food Systems and Skagit County Extension as part of 209 | the USDA NRCS Innovation in Conservation program, led by Viva Farms 210 | (grant number NR22-13G004). 211 | -------------------------------------------------------------------------------- /pkgdown/index.md: -------------------------------------------------------------------------------- 1 | 2 | # soils 3 | 4 | 5 | 6 | [![Project Status: WIP – Initial development is in progress, but there 7 | has not yet been a stable, usable release suitable for the 8 | public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip) 9 | 10 | [![CRAN 11 | status](https://www.r-pkg.org/badges/version/soils)](https://CRAN.R-project.org/package=soils) 12 | [![:name status 13 | badge](https://wa-department-of-agriculture.r-universe.dev/badges/:name)](https://wa-department-of-agriculture.r-universe.dev/) 14 | [![soils status 15 | badge](https://wa-department-of-agriculture.r-universe.dev/badges/soils)](https://wa-department-of-agriculture.r-universe.dev/soils) 16 | [![R-CMD-check](https://github.com/WA-Department-of-Agriculture/soils/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/WA-Department-of-Agriculture/soils/actions/workflows/R-CMD-check.yaml) 17 | 18 | 19 | 20 | 📢 **Announcing Dirt Data Reports: a no-code soil health reporting tool 21 | built on {soils} using Shiny** 22 | 23 | 👉 Try it [here](https://wsda.shinyapps.io/dirt-data-reports/) if you 24 | don’t need full customization or prefer not to code. 25 | 26 | 📖 Read more about it in this [blog 27 | post](https://washingtonsoilhealthinitiative.com/2025/09/dirt-data-reports/). 28 | 29 | # Overview 30 | 31 | {soils} is an R package for all your soil health data visualization and 32 | reporting needs. {soils} provides an RStudio project template to 33 | generate customized, interactive soil health reports. These reports 34 | include plots and tables to show how the participant’s results compare 35 | to simple averages of results from samples of the same crop, same 36 | county, and across the entire project. 37 | 38 | Any scientist leading a soil health survey can use {soils} to create 39 | custom reports for all participants. Democratize your data by giving 40 | back to the farmers and land managers who contributed soil samples to 41 | your soil sampling project. Use these reports to empower each 42 | participant to explore and better understand their data. 43 | 44 | The [Washington State Department of 45 | Agriculture](https://agr.wa.gov/departments/land-and-water/natural-resources/soil-health) 46 | and [Washington State University](https://soilhealth.wsu.edu/) developed 47 | {soils} as part of the [Washington Soil Health 48 | Initiative](https://washingtonsoilhealthinitiative.com/). Learn more 49 | about {soils} in this [blog 50 | post](https://washingtonsoilhealthinitiative.com/2024/03/soils-an-r-package-for-soil-health-reporting/) 51 | or this [webinar](https://youtu.be/_8m7fTjSEOk?si=ikrCASdchiB6rDC2). 52 | 53 | # Requirements 54 | 55 | The report template uses [Quarto](https://quarto.org/docs/get-started/), 56 | which is the 57 | [next-generation](https://quarto.org/docs/faq/rmarkdown.html) version of 58 | [R Markdown](https://quarto.org/docs/faq/rmarkdown.html). 59 | 60 | We assume you’re using [RStudio 61 | v2022.07](https://dailies.rstudio.com/version/2022.07.2+576.pro12/) or 62 | later for editing and previewing Quarto documents. We **strongly 63 | recommend** you use the [latest release of 64 | RStudio](https://posit.co/download/rstudio-desktop/) for support of all 65 | Quarto features. You can also download and install the [latest version 66 | of Quarto](https://quarto.org/docs/get-started/) independently from 67 | RStudio. 68 | 69 | To render Microsoft Word (MS Word) documents, you must have MS Word 70 | installed and activated. 71 | 72 | **If you’re new to Quarto and Markdown formatting syntax, first take a 73 | look at the Primers on 74 | [Quarto](https://wa-department-of-agriculture.github.io/soils/articles/quarto.html) 75 | and 76 | [Markdown](https://wa-department-of-agriculture.github.io/soils/articles/markdown.html) 77 | to learn how they’re used in {soils} and get familiar with their 78 | features.** 79 | 80 | # Installation 81 | 82 | Install the development version of {soils} from our 83 | [r-universe](https://wa-department-of-agriculture.r-universe.dev/) with: 84 | 85 | ``` r 86 | install.packages( 87 | "soils", 88 | repos = c("https://wa-department-of-agriculture.r-universe.dev") 89 | ) 90 | ``` 91 | 92 | Or install from GitHub with [{pak}](https://pak.r-lib.org/index.html): 93 | 94 | ``` r 95 | # Uncomment the below line if {pak} is not installed. 96 | # install.packages("pak") 97 | pak::pkg_install("WA-Department-of-Agriculture/soils") 98 | ``` 99 | 100 | Load the example datasets and functions with: 101 | 102 | ``` r 103 | library(soils) 104 | ``` 105 | 106 | # Usage 107 | 108 | {soils} was developed to work ‘out of the box’ so you can immediately 109 | install and render an example report. However, you will need to 110 | customize and edit content to fit your project. 111 | 112 | Our recommended workflow is to **1)** create a new {soils} project, 113 | **2)** try to render the example reports to make sure everything works 114 | on your system, and **3)** customize the template files to use your own 115 | data, content, and styling. 116 | 117 | We provide a series of [Primers and 118 | Tutorials](https://wa-department-of-agriculture.github.io/soils/articles/index.html) 119 | to prepare and guide you through this workflow. See below for short demo 120 | videos and links to the relevant tutorials. 121 | 122 | ## 1. Create a new {soils} project 123 | 124 | Follow along in the [**Create a {soils} 125 | project**](https://wa-department-of-agriculture.github.io/soils/articles/project.html) 126 | tutorial. Choose between two report templates: **English** or 127 | **Spanish**. 128 | 129 | 132 | 133 | ## 2. Render the example reports 134 | 135 | Follow along in the [**Render the example 136 | reports**](https://wa-department-of-agriculture.github.io/soils/articles/render-example.html) 137 | tutorial. 138 | 139 | See the [**rendered example 140 | reports**](https://wa-department-of-agriculture.github.io/soils/articles/examples.html). 141 | 142 | ### HTML 143 | 144 | 147 | 148 | ### MS Word 149 | 150 | 153 | 154 | ## 3. Create reports with your own data 155 | 156 | To use your own data, customize the reports for your project, and render 157 | all reports, follow along with these tutorials: 158 | 159 | - [**Import 160 | data**](https://wa-department-of-agriculture.github.io/soils/articles/data.html) 161 | 162 | - [**Customize & 163 | write**](https://wa-department-of-agriculture.github.io/soils/articles/customize.html) 164 | 165 | - [**Render 166 | reports**](https://wa-department-of-agriculture.github.io/soils/articles/render.html) 167 | 168 | 171 | 172 | ## Troubleshooting 173 | 174 | As you edit the content, errors are bound to occur. Read [**tips and 175 | workflows for 176 | troubleshooting**](https://wa-department-of-agriculture.github.io/soils/articles/troubleshoot.html) 177 | 178 | # Acknowledgement and citation 179 | 180 | The below acknowledgement is automatically embedded in each report: 181 | 182 | > This report was generated using the [{soils} R 183 | > package](https://wa-department-of-agriculture.github.io/soils/). 184 | > {soils} was developed by the Washington State Department of 185 | > Agriculture and Washington State University, as part of the Washington 186 | > Soil Health Initiative. Text and figures were adapted from [WSU 187 | > Extension publication \#FS378E Soil Health in Washington 188 | > Vineyards](https://pubs.extension.wsu.edu/soil-health-in-washington-vineyards). 189 | > Learn more about {soils} in this [blog 190 | > post](https://washingtonsoilhealthinitiative.com/2024/03/soils-an-r-package-for-soil-health-reporting/) 191 | > or this [webinar](https://youtu.be/_8m7fTjSEOk?si=ikrCASdchiB6rDC2). 192 | 193 | To cite {soils} in publications, please use: 194 | 195 | > Ryan JN, McIlquham M, Sarpong KA, Michel LM, Potter TS, Griffin LaHue 196 | > D, Gelardi DL. 2024. Visualize and Report Soil Health Data with 197 | > {soils}. Washington Soil Health Initiative. 198 | > 199 | 200 | ## Credits 201 | 202 | {soils} adapts from existing R project templating resources and 203 | packages: 204 | 205 | - [RStudio Project 206 | Templates](https://rstudio.github.io/rstudio-extensions/rstudio_project_templates.html) 207 | - [{ratlas}](https://github.com/atlas-aai/ratlas) 208 | - [{quartotemplate}](https://github.com/Pecners/quartotemplate) 209 | - [{golem}](https://github.com/ThinkR-open/golem/) 210 | 211 | Text and figures were adapted from [WSU Extension publication \#FS378E 212 | Soil Health in Washington 213 | Vineyards](https://pubs.extension.wsu.edu/soil-health-in-washington-vineyards). 214 | 215 | Report text and images were translated by Erica Tello, Eber Rivera, and 216 | Kate Smith with WSU Food Systems and Skagit County Extension as part of 217 | the USDA NRCS Innovation in Conservation program, led by Viva Farms 218 | (grant number NR22-13G004). 219 | --------------------------------------------------------------------------------