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
# Add custom error messages to specific errors in R | |
error_handler <- function() { | |
rlang::entrace() | |
e <- rlang::last_error()$message | |
if (grepl("there is no package called", x = e)) { | |
message("* This can be a custom error message with multiple lines.") | |
} | |
} | |
if ("rlang" %in% rownames(installed.packages())) { |
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
#' Flatten copy | |
#' | |
#' @param from Source directory path. | |
#' @param to Destination directory path. | |
#' | |
#' @return Destination directory path. | |
#' | |
#' @details | |
#' Copy all `.Rmd`, `.qmd`, and `.md` files from source to destination, | |
#' rename the `.qmd` and `.md` files with an additional `.Rmd` extension, |
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
--- | |
title: "Click to change to a random superlative" | |
output: html_document | |
--- | |
From <https://www.garrickadenbuie.com/blog/countdown-v0.4.0/>. | |
I'm <span class="superlative">overjoyed</span> to announce that... | |
```{css} |
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
# Clone repo | |
git clone https://github.com/keaven/gsDesign.git | |
cd gsDesign | |
# Run gource - this will generate a 411GB ppm file | |
gource -3840x2160 --seconds-per-day 0.1 --auto-skip-seconds 0.01 --file-idle-time 0 --font-size 34 --key --logo man/figures/logo.png -o gsDesign.ppm | |
# Convert ppm to mp4 | |
ffmpeg -y -r 60 -f image2pipe -vcodec ppm -i gsDesign.ppm -vcodec libx264 -preset medium -pix_fmt yuv420p -crf 1 -threads 0 -bf 0 gsDesign.mp4 | |
# Merge audio to video | |
ffmpeg -i gsDesign.mp4 -i music.mp3 -c:v copy -c:a aac output.mp4 | |
# Recommended by YouTube |
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
// Automate browser extension updates with RobotJS | |
const robot = require("robotjs"); | |
const { execSync } = require("child_process"); | |
const updateExtension = (coordRemove) => { | |
// Open in extensions page in browser | |
execSync('open -a "Google Chrome" chrome://extensions'); | |
// Move to and click "Remove" button of the extension | |
robot.setMouseDelay(1000); |
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
# Load data and split training/test set ---------------------------------------- | |
library("xts") | |
index2010 <- sparseIndexTracking::INDEX_2010 | |
x_tr <- index2010$X[1:126] | |
x_te <- index2010$X[127:252] | |
r_tr <- index2010$SP500[1:126] | |
r_te <- index2010$SP500[127:252] |
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
library("promises") | |
library("chromote") | |
#' Print HTML to PDF using chromote | |
#' | |
#' @param url Input URL | |
#' @param filename Output file name | |
#' @param wait_ If TRUE, run in synchronous mode, | |
#' otherwise, run in asynchronous mode. | |
#' @param ... Additional parameters for Page.printToPDF, see |
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
# <https://github.com/madler/zlib/blob/8678871f18f4dd51101a9db1e37791f975969079/doc/txtvsbin.txt> | |
#' Classify any file into text file or binary file | |
#' | |
#' @param path File path. | |
#' @param n The (maximal) number of bytes to read. | |
#' | |
#' @return Logical. `TRUE` if text, `FALSE` if binary. | |
#' | |
#' @examples |
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
# Get operator (parallel or serial) | |
# Idea from <https://github.com/tidymodels/tune/blob/c4a1d891ac77e64086a417ab75ad822178cd87ee/R/parallel.R> | |
get_operator <- function() { | |
is_par <- foreach::getDoParWorkers() > 1 | |
if (is_par) { | |
res <- foreach::`%dopar%` | |
} else { | |
res <- foreach::`%do%` | |
} | |
res |
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
fileInputArea <- function(inputId, label, multiple = FALSE, accept = NULL, | |
width = NULL, buttonLabel = "Browse...", placeholder = "No file selected") { | |
restoredValue <- restoreInput(id = inputId, default = NULL) | |
# Catch potential edge case - ensure that it's either NULL or a data frame. | |
if (!is.null(restoredValue) && !is.data.frame(restoredValue)) { | |
warning("Restored value for ", inputId, " has incorrect format.") | |
restoredValue <- NULL | |
} |