Last updated: 2023-02-20

Checks: 7 0

Knit directory: dwc_o2p/

This reproducible R Markdown analysis was created with workflowr (version 1.7.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20230220) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 3bfa4b2. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/

Untracked files:
    Untracked:  data/dwc_db/emof_soils.csv

Unstaged changes:
    Modified:   analysis/index.Rmd

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/prepara_dwc_o2p_suelo.Rmd) and HTML (docs/prepara_dwc_o2p_suelo.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 3bfa4b2 ajpelu 2023-02-20 prepare suelos
Rmd bc2e3db ajpelu 2023-02-20 move

Datos originales

Partimos del archivo exporatado de la base de datos como suelos_v2.xlsx que está en la ruta data_raw/suelos_v2.xlsx

library(tidyverse) # Easily Install and Load the 'Tidyverse'
library(here) # A Simpler Way to Find Your Files
library(janitor) # Simple Tools for Examining and Cleaning Dirty Data
library(DT)
raw <- readxl::read_excel(here::here("data/raw/suelos_v2.xlsx")) |> 
  janitor::clean_names()

Al importar los datos aplicamos una “limpieza de los nombres de las variables” para que sean mas manejables de forma programática. Usamos para ello la función janitor::clean_names (eg. “K %” se convierte en k_percent)

Estandarización de campos:

  • nombre_zona: renombramos la variable a treatment_name, y los niveles del factor los renombramos

    • “Quemado con pastoreo”: QOP
    • “Quemado sin pastoreo”: QONP
    • “Quemado primavera”: QPP
  • geo_parcela_nombre lo estandarizamos con la estructura XX_00 siendo XX: P (Pastoreo), NP (No Pastoreo), PR (Primavera) y 00 correspoden a unos números. Ojo tenemos que añadir un 0 a algunos números

  • fecha lo convierto a formato ’YYYYMMDD`

  • geo_suelos_nombre. De esta columna nos interesa obtener la réplica, que nos informaría del rango de vegetación. O también podemos obviarlo en nombre del evento, y añadirlo como una variable.

raw_event_long <- raw |> 
  mutate(
    treatment_name = case_when(
      nombre_zona == "Quemado con pastoreo" ~ "QOP",
      nombre_zona == "Quemado sin pastoreo" ~ "QONP",
      nombre_zona == "Quemado primavera" ~ "QPP")) |> 
  separate(col = geo_parcela_nombre, 
           into = c("gpname", "gpnumber"), remove = FALSE) |> 
  mutate(gpnumber = sprintf("%02d",as.numeric(gpnumber))) |> 
  unite(col = "geo_parcela_nombre0", gpname:gpnumber, sep = "") |> 
  mutate(date = gsub("-","",fecha)) |> 
    mutate(replica = 
           ifelse(rango != "Intermedia",
                  paste0("R",rango), 
                  str_extract(geo_suelos_nombre, 'E\\d+'))) |> 
  unite("aux", c(geo_parcela_nombre0,replica), sep = "", remove = FALSE) |>
  unite("eventID", c(aux, date), remove = FALSE) |> 
  dplyr::select(
    eventID, 
    treatment_name, 
    measurementDeterminedDate = date, 
    ptotal_percent:p_h_k_cl) |> 
  pivot_longer(cols = -c(eventID, treatment_name, measurementDeterminedDate), 
               names_to = "raw_key", values_to = "measurementValue")
  • Uno con los nombres de las variables
dicc_variables <- read.csv(here::here("data/raw/dic_var.csv"), sep = ";", 
                           encoding = 'UTF-8') |> 
  rename(measurementType = name_var,
         measurementUnit = units,
         measurementMethod = methods,
         measurementRemarks = url_controlled)
emof_soils <- raw_event_long |> 
  inner_join(dicc_variables) |> 
  unite("measurementID", c(eventID, id), remove = FALSE) |> 
  dplyr::select(measurementID, 
                eventID,
                measurementType,
                measurementValue,
                measurementUnit,
                measurementDeterminedDate,
                measurementMethod, 
                measurementRemarks) |> 
  filter(!is.na(measurementValue))
Joining, by = "raw_key"

La tabla se exporta en csv en el siguiente enlace data/dwc_db/emof_soils.csv.

# Export table
write_csv(emof_soils, 
          here::here("data/dwc_db/emof_soils.csv"))

Aspecto de la tabla:


sessionInfo()
R version 4.2.1 (2022-06-23)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Monterey 12.3.1

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] DT_0.26         janitor_2.1.0   here_1.0.1      forcats_0.5.2  
 [5] stringr_1.4.1   dplyr_1.0.10    purrr_0.3.5     readr_2.1.3    
 [9] tidyr_1.2.1     tibble_3.1.8    ggplot2_3.4.0   tidyverse_1.3.2
[13] workflowr_1.7.0

loaded via a namespace (and not attached):
 [1] httr_1.4.4          sass_0.4.4          bit64_4.0.5        
 [4] vroom_1.6.0         jsonlite_1.8.4      modelr_0.1.9       
 [7] bslib_0.4.2         assertthat_0.2.1    getPass_0.2-2      
[10] googlesheets4_1.0.1 cellranger_1.1.0    yaml_2.3.7         
[13] pillar_1.8.1        backports_1.4.1     glue_1.6.2         
[16] digest_0.6.31       promises_1.2.0.1    rvest_1.0.3        
[19] snakecase_0.11.0    colorspace_2.0-3    htmltools_0.5.4    
[22] httpuv_1.6.8        pkgconfig_2.0.3     broom_1.0.1        
[25] haven_2.5.1         scales_1.2.1        processx_3.7.0     
[28] whisker_0.4         later_1.3.0         tzdb_0.3.0         
[31] git2r_0.30.1        googledrive_2.0.0   generics_0.1.3     
[34] ellipsis_0.3.2      cachem_1.0.6        withr_2.5.0        
[37] cli_3.6.0           magrittr_2.0.3      crayon_1.5.2       
[40] readxl_1.4.1        evaluate_0.18       ps_1.7.1           
[43] fs_1.5.2            fansi_1.0.3         xml2_1.3.3         
[46] tools_4.2.1         hms_1.1.2           gargle_1.2.1       
[49] lifecycle_1.0.3     munsell_0.5.0       reprex_2.0.2       
[52] callr_3.7.3         compiler_4.2.1      jquerylib_0.1.4    
[55] rlang_1.0.6         grid_4.2.1          rstudioapi_0.14    
[58] htmlwidgets_1.5.4   crosstalk_1.2.0     rmarkdown_2.18     
[61] gtable_0.3.1        DBI_1.1.3           R6_2.5.1           
[64] lubridate_1.8.0     knitr_1.41          bit_4.0.4          
[67] fastmap_1.1.0       utf8_1.2.2          rprojroot_2.0.3    
[70] stringi_1.7.8       parallel_4.2.1      Rcpp_1.0.9         
[73] vctrs_0.5.1         dbplyr_2.2.1        tidyselect_1.2.0   
[76] xfun_0.35