Last updated: 2023-07-26
Checks: 7 0
Knit directory: ms_mariposas_pheno/
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(20230601) 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 fe2a4eb. 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/
Ignored: data/raw_data/.DS_Store
Untracked files:
Untracked: data/best_models_prec.csv
Untracked: data/best_models_prec.xlsx
Untracked: data/best_models_temp.csv
Untracked: data/best_models_temp.xlsx
Untracked: data/doy_medio_sp.csv
Untracked: data/doy_medio_sp.xlsx
Untracked: data/models_prec_scaled.csv
Untracked: data/models_prec_scaled.xlsx
Untracked: data/models_tmed_scaled.csv
Untracked: data/models_tmed_scaled.xlsx
Unstaged changes:
Modified: analysis/climate_sensibility.Rmd
Modified: analysis/index.Rmd
Modified: data/models_prec.csv
Modified: data/models_prec.xlsx
Modified: data/models_tmed.csv
Modified: data/models_tmed.xlsx
Modified: data/selected_species.csv
Modified: data/transectos_climate.csv
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/prepare_peak.Rmd) and HTML
(docs/prepare_peak.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 | fe2a4eb | ajpelu | 2023-07-26 | peak data |
| html | 124ca91 | ajpelu | 2023-06-01 | Build site. |
| Rmd | bb25c0d | ajpelu | 2023-06-01 | remove msg |
| html | 7b1115c | ajpelu | 2023-06-01 | Build site. |
| Rmd | 4e306f7 | ajpelu | 2023-06-01 | prepare peak by species |
library(tidyverse)
library(here)
library(janitor)
library(lubridate)
library(ggpubr)
# Read the transect data
transectos <- read_csv(here::here("data/transectos_metadata.csv"))
JMBA give the a folder with files for each species of the curve
fitted by year and site (/raw_data/pheno_sp)
We prepare the data: read the data, join the transects metadata and then compute the day of year with the maximum fitted valued (peak_day)
There are problems with the files:
Glaucopsyche_alexis_BMSSN_pheno.xlsx and
Libythea_celtis_BMSSN_pheno.xlsx. We removed them into
folder (/raw_data/pheno_sp_novalid)
I wrote a custom function to read the data, unite year, month and
day and convert it into date. Then compute the day of year
(doy), generate a dataframe (pheno) and export
the data as /data/pheno.csv
# List the files
pheno_files <- list.files(here::here("data/raw_data/pheno_sp/"), pattern = "*pheno.xlsx", full.names = TRUE)
prepare_pheno <- function(file) {
df_pheno <- readxl::read_excel(file) |>
janitor::clean_names() |>
mutate(date = lubridate::make_date(year, month, day)) |>
mutate(doy = lubridate::yday(date))
return(df_pheno)
}
pheno <- purrr::map_df(pheno_files, ~ prepare_pheno(.))
write_csv(pheno, here::here("data/pheno.csv"))
The dataframe pheno has 203134 records.
We extract the doy (day of the year) for each species, sites and
year with the maximum peak of the fitted valued. For this purpose we
write a custom function get_peak_day. The dataframe
pheno contains some records with NA value in
site_id and also some data with NA values in
fitted variable. So we remove them using the option
na.rm in the function dplyr::slice_max. The
information about transect was joined. The output results is exported as
data/doy_peak_sps.csv)
get_peak_day <- function(df_pheno) {
peak_day <- df_pheno |>
group_by(species, site_id, year) |>
slice_max(fitted, na_rm = TRUE) |>
dplyr::select(species, site_id, year,
month, day, week,
fitted, date, doy) |>
ungroup()
return(peak_day)
}
doy_peak_sps <- get_peak_day(pheno) |>
inner_join(transectos)
write_csv(doy_peak_sps, here::here("data/doy_peak_sps.csv"))
sessionInfo()
R version 4.2.3 (2023-03-15)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur ... 10.16
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/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] ggpubr_0.4.0 janitor_2.1.0 here_1.0.1 lubridate_1.9.2
[5] forcats_1.0.0 stringr_1.5.0 dplyr_1.1.0 purrr_1.0.1
[9] readr_2.1.4 tidyr_1.3.0 tibble_3.1.8 ggplot2_3.4.1
[13] tidyverse_2.0.0 workflowr_1.7.0
loaded via a namespace (and not attached):
[1] Rcpp_1.0.10 getPass_0.2-2 ps_1.7.1 rprojroot_2.0.3
[5] digest_0.6.31 utf8_1.2.2 cellranger_1.1.0 R6_2.5.1
[9] backports_1.4.1 evaluate_0.19 httr_1.4.4 pillar_1.8.1
[13] rlang_1.1.0 readxl_1.4.2 rstudioapi_0.14 whisker_0.4
[17] car_3.1-0 callr_3.7.3 jquerylib_0.1.4 rmarkdown_2.19
[21] bit_4.0.4 munsell_0.5.0 broom_1.0.4 compiler_4.2.3
[25] httpuv_1.6.8 xfun_0.39 pkgconfig_2.0.3 htmltools_0.5.4
[29] tidyselect_1.2.0 fansi_1.0.3 crayon_1.5.2 tzdb_0.3.0
[33] withr_2.5.0 later_1.3.0 grid_4.2.3 jsonlite_1.8.4
[37] gtable_0.3.1 lifecycle_1.0.3 git2r_0.30.1 magrittr_2.0.3
[41] scales_1.2.1 vroom_1.6.3 carData_3.0-5 cli_3.6.0
[45] stringi_1.7.8 cachem_1.0.6 ggsignif_0.6.3 fs_1.6.2
[49] promises_1.2.0.1 snakecase_0.11.0 bslib_0.4.2 ellipsis_0.3.2
[53] generics_0.1.3 vctrs_0.6.0 tools_4.2.3 bit64_4.0.5
[57] glue_1.6.2 hms_1.1.2 parallel_4.2.3 abind_1.4-5
[61] processx_3.7.0 fastmap_1.1.0 yaml_2.3.7 timechange_0.1.1
[65] colorspace_2.0-3 rstatix_0.7.0 knitr_1.41 sass_0.4.5