Skip to content

Instantly share code, notes, and snippets.

@olivroy
olivroy / error-msg.r
Created June 28, 2024 19:23
Error messagess
f_error <- function(arg, msg, call = rlang::caller_env()) {
if (TRUE) {
# THe naive way
cli::cli_abort(c("{.arg {arg}} is wrong", msg), call = call)
}
}
f_error2 <- function(arg, msg, call = rlang::caller_env(), .envir = parent.frame()) {
if (TRUE) {
# doesn't work since arg needs to evaluate in current frame, but msg should evaluate in parent frame
cli::cli_abort(c("{.arg {arg}} is wrong", msg), call = call, .envir = .envir)
mat <- matrix(
  c(1, 2, 3, 4),
  nrow = 2
)
mat
#>      [,1] [,2]
#> [1,]    1    3
#> [2,]    2    4
indice &lt;- integer(0) # mimic `which()` result if nothing found.
@olivroy
olivroy / .lintr
Last active May 16, 2024 01:35
My linter file
linters: all_linters(
# packages = "lintr",
line_length_linter = NULL,
namespace_linter = NULL,
todo_comment_linter = NULL,
cyclocomp_linter = NULL,
duplicate_argument_linter = NULL, # cli_abort...
object_usage_linter = NULL, # problem
implicit_integer_linter = NULL,
object_length_linter = NULL, # will not rename objects
@olivroy
olivroy / openxlsx2-functions.R
Last active August 22, 2023 03:27
Explore function use in `openxlsx2`
# this script counts the frequency of function use in order to create a function index that make more sense.
# We want to look at what is more user facing.
# for now the data source we use is the examples, vignettes, README etc.
# Maybe some blog posts in the wild may be used eventually.
# TODO go get functions that are used in chaining, and add back `wb_` prefix
# TODO reorder R6 methods so that internal ones are not shown first in documentation
# TODO add_thread, suggest `create_person()` or link to `wb_creators()`, `wb_person()`,
# TODO validate that `wb_dims()`, `wb_color()` are similar to
# TODO validate vignette content. discuss if the long / complicated way to add styling is relevant in the vignette.
# TODO prefixer https://github.com/dreamRs/prefixer
@olivroy
olivroy / .Rprofile
Last active April 22, 2024 02:04
Deprecated, moved to elsewhere
# if (FALSE && rlang::is_interactive()) {
if (interactive() && !"rlang" %in% rownames(utils::installed.packages())) utils::install.packages("rlang", type = "binary")
# options(rlang_interactive = FALSE)
if (interactive()) rlang::check_installed(c("pak", "rprojroot", "tidyverse", "gt", "quarto", "skimr", "kit", "sf"))
# my packages
# if (interactive()) {
# invisible(pak::repo_add(sfirke = "https://sfirke.r-universe.dev", olivroy = "https://olivroy.r-universe.dev"))
# }
c('TrucRegion') |>
stringr::str_replace_all("([:lower:])([:upper:])", "\\1 \\2")
@olivroy
olivroy / rmarkdown.Rmd
Last active February 15, 2022 15:26
Some specifications for Rmd doc.
---
output:
bookdown::html_document2:
theme: bootstrap
version: 5
highlight: kate
---
```{r setup, include=FALSE}
library(knitr)