Skip to content

Instantly share code, notes, and snippets.

View philipp-baumann's full-sized avatar
:atom:
Sensing the environment. WhoeverWhatever-Cares.

Philipp Baumann philipp-baumann

:atom:
Sensing the environment. WhoeverWhatever-Cares.
View GitHub Profile
@philipp-baumann
philipp-baumann / get_nix_arrow_env.R
Created April 21, 2024 17:23
Get nix environment with R and arrow
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(
@philipp-baumann
philipp-baumann / rix-rstudio-aarch-darwin_logs.txt
Created February 27, 2024 19:21
rix-rstudio-aarch-darwin_logs.txt
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 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
@philipp-baumann
philipp-baumann / test-with_nix.R
Last active January 6, 2024 19:09
Testing new {rix} with_nix()
# 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")
@philipp-baumann
philipp-baumann / snv-benchmark.R
Last active August 22, 2023 20:11
snv-benchmark.R
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), `-`)
@philipp-baumann
philipp-baumann / average-spc.R
Created April 15, 2020 08:14
simplerspec: Average spectra in list-column by entries in grouping column
#' @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
## 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
@philipp-baumann
philipp-baumann / _setup-run-all.R
Created October 7, 2019 17:28
Plan and build targets
## 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(
{
"R": {
"Version": "3.6.1",
"Repositories": [
{
"Name": "CRAN",
"URL": "https://cloud.r-project.org"
}
]
},
{
"renv": {
"Version": "0.6.0-61"
},
"R": {
"Version": "3.6.1",
"Repositories": [
{
"Name": "CRAN",
"URL": "https://cloud.r-project.org"