This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!require("rix")) { | |
if (!require("remotes") install.packages("remotes") | |
remotes::install_github("b-rodrigues/rix") | |
} | |
library("rix") | |
# make sure that only nix library paths in /nix/... are used to load R packages | |
rix_init() | |
# define `default.nix` in reproducible manner (will ping nixpkgs revision on GitHub) | |
rix( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CMake Warning: | |
Manually-specified variables were not used by the project: | |
BUILD_TESTING | |
CMAKE_EXPORT_NO_PACKAGE_REGISTRY | |
CMAKE_POLICY_DEFAULT_CMP0025 | |
QT_QMAKE_EXECUTABLE | |
-- Build files have been written to: /tmp/nix-build-RStudio-2023.09.0+463.drv-1/source/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file was generated by the {rix} R package v0.4.1 on 2024-01-06 | |
# with following call: | |
# >rix(r_ver = "63143ac2c9186be6d9da6035fa22620018c85932", | |
# > r_pkgs = c("dplyr", | |
# > "data.table"), | |
# > overwrite = TRUE) | |
# It uses nixpkgs' revision 63143ac2c9186be6d9da6035fa22620018c85932 for reproducibility purposes | |
# which will install R version latest | |
# Report any issues to https://github.com/b-rodrigues/rix | |
let |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install_github("b-rodrigues/rix", ref = "71-with-nix") | |
library("rix") | |
library("dplyr") | |
library("data.table") | |
# fusen::load_flat_functions(flat_file = "dev/build_envs.Rmd") | |
# fusen::load_flat_functions(flat_file = "dev/get_os.Rmd") | |
library("rix") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
snv_impl_base <- function(X) { | |
X <- as.matrix(X) | |
X <- sweep(X, 1L, rowMeans(X, na.rm = TRUE), `-`) | |
X_sc <- sweep(X, 1L, apply(X, 1L, sd, na.rm = TRUE), `/`) | |
return(X_sc) | |
} | |
snv_impl_base_mstats <- function(X) { | |
X <- as.matrix(X) | |
X <- sweep(X, 1L, matrixStats::rowMeans2(X, na.rm = TRUE), `-`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' @title Average spectra in list-column by entries in grouping column | |
#' @description Average spectra in list-column of spectra tibble (`spc_tbl`) by | |
#' groups given in group column. | |
#' @param spc_tbl Tibble data frame containing at least the grouping column | |
#' given in argument `by` and input spectra given in list-column `column_in`. | |
#' @param by Character vector of length 1L or name/symbol that specifies the | |
#' column by which groups of spectra are averaged. Default is `"sample_id"`. | |
#' @param column_in Character vector of length 1L or or name/symbol that | |
#' specifies the list-column that contains the inputs spectra to be averaged. | |
#' Default is `"spc_rs"`, which are resampled spectra (i.e., resulting after |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Wrangle results of nested group k-fold cross-validation ===================== | |
# Add additional grouping IDs | |
cubist_nested_results_ids <- cubist_nested_add_ids( | |
object = cubist_nested_results_repgroupcv, x_vars = "spc_pre", | |
id_cols = c("site_id", "depth_cm"), | |
y_vars = param_names, | |
custom_spc_averaging = FALSE) | |
# Get predicted and observed values for each outer resample assessment set |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Load packages | |
pkgs <- c("here", "drake", "tidyverse", "data.table", | |
"simplerspec", "caret", "Cubist", "rsample", "nls.multstart", | |
"broom", # modeling | |
"future", "future.apply", "doParallel", "doFuture", # asynchronous computation | |
"gghighlight", "grid", "gridExtra", "cowplot", # graphics | |
"xtable") # tables | |
purrr::walk(pkgs, library, character.only = TRUE) | |
funs <- list( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"R": { | |
"Version": "3.6.1", | |
"Repositories": [ | |
{ | |
"Name": "CRAN", | |
"URL": "https://cloud.r-project.org" | |
} | |
] | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"renv": { | |
"Version": "0.6.0-61" | |
}, | |
"R": { | |
"Version": "3.6.1", | |
"Repositories": [ | |
{ | |
"Name": "CRAN", | |
"URL": "https://cloud.r-project.org" |
NewerOlder