This file contains hidden or 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
for (i in 1:5) { | |
chapter <- paste0("chapter-", i) | |
path <- file.path("~", "advanced-concepts-in-shiny", "exercises", chapter, "question") | |
usethis::create_project(path = path, rstudio = TRUE, open = FALSE) | |
file.rename( | |
from = file.path(path, "question.Rproj"), | |
to = file.path(path, paste0("ch", i, "-question.Rproj")) | |
) | |
} |
This file contains hidden or 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
# An issue with the lintr pre-commit hook is that packages are not fully loaded | |
# prior to linting, so you can get lots of object-usage lints when an object from | |
# your dev packages namespace is used. | |
# | |
# The following ensures your dev package is loaded before linting the changed | |
# files within it. It requires {lintr} to be installed in your dev environment. | |
# This differs from most pre-commit hooks (which usually run in a hook-specific | |
# renv environment) | |
# | |
# All available hooks: https://pre-commit.com/hooks.html |
This file contains hidden or 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
[alias] | |
biff = "!f() { \ | |
# all changes since branch/hash $2 separated from branch/hash $1 \ | |
old=${1:-main}; new=${2:-HEAD}; base=$(git merge-base ${old} ${new}); \ | |
git diff ${base} ${new}; \ |
This file contains hidden or 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
# Run the test file multiple times, break when it fails to pass | |
TEST_PATTERN="xxx" | |
for i in {1..10}; do | |
npx jest ${TEST_PATTERN} --silent --runInBand; | |
if [[ "$?" != 0 ]]; then echo "Failed after $i attempts" && break; fi; | |
done |
This file contains hidden or 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
# compare the object-usage lints obtained before/after a given PR | |
# the PR is always compared against master | |
library(magrittr) | |
library(dplyr) | |
library(purrr) | |
library(tibble) | |
# In lintr directory |
This file contains hidden or 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
# My rscript template assumes all command line arguments are in option-form | |
# `Rscript <script_name> --logical_option --some_flag some_value --some_other_flag some_other_value` | |
# | |
# When you want to pass a variable number of files into your script, the option-form doesn't work well | |
# so it's better to use trailing arguments | |
# `Rscript <script_name> --some_option --flag with_value trailing1 trailing2 trailing3 ...` | |
# | |
# optparse works well in the latter case: | |
library(magrittr) |
This file contains hidden or 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
# My title | |
```{r} | |
tables <- list(a = iris[1:10, ], b = iris[11:20, ]) | |
``` | |
```{r} | |
#' When makinig an Rmarkdown, this function will print all the data.frames | |
#' in a list | |
#' |
This file contains hidden or 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
linters: with_defaults( | |
# By using the `with_defaults` function in .lintr to set up the linters for your package / project, | |
# you are telling {lintr}: start with this named-list of linters (given in the argument `default`, | |
# see below) and modify any that I specify. | |
# Here, that means you want to use the list `default_linters`, but modify that list. | |
# | |
# See `names(lintr::default_linters)` for the contents of the `default_linters` used here. | |
# | |
# You could alternatively | |
# |
This file contains hidden or 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
#!/usr/bin/env Rscript | |
############################################################################### | |
# Package names for non-test dependencies | |
pkgs <- c( | |
# CRAN | |
"magrittr", | |
"optparse", | |
# Bioconductor |