Skip to content

Instantly share code, notes, and snippets.

View maurolepore's full-sized avatar

Mauro Lepore maurolepore

View GitHub Profile

Unboken lines make it difficult to see what changes:

  • In stat_bin(), binwidth now also takes functions. The function is called with the scaled x values, and should return a single number. With little work, this makes it possible to use classical bin size computations with ggplot2.

Lines wrapped at 80 characters make it easy to see what changes:

  • In stat_bin(), binwidth now also takes functions. The function is called with the scaled x values, and should return a single number.

Here: https://git.io/JrwgD

--

This code

reprex::reprex({
  library(dplyr, warn.conflicts = FALSE)
 library(r2dii.plot)

Here: https://git.io/Jw3JJ

--

This code

reprex::reprex(wd = ".", {
  library(devtools)
  run_examples(start = "scale_fill_r2dii")
library(fs)

files <- c("a", "b")
path_ext_set(files, ".csv")
#> a.csv b.NA

Created on 2021-10-05 by the reprex package (v2.0.1)

@maurolepore
maurolepore / ipr.md
Last active September 29, 2021 17:15
# End of web tool script 2

library(ipr)
results <- exclude_ipr_results(
  from = "path/to/results",
  move_to = "path/to/ipr_results"
 )

# "path/to/results" now has results of normal scenarios only

From ?lubridate::dmy_hms: "Arguments: ... a character vector of dates in year, month, day, hour, minute, second format.

This means you don't need to write a for loop because someone already wrote it for you. In Jenny's words:

Of course someone has to write for loops. It doesn't have to be you. -- Jenny Bryan (row-oriented workflows)

library(lubridate, warn.conflicts = FALSE)
library(dplyr, warn.conflicts = FALSE)
@maurolepore
maurolepore / paths.md
Last active September 14, 2021 12:49
path_all_users <- "/path/to/all_users"
user_list <- c("user_1", "user_2")

# What you want: Same but simpler
path <- file.path(path_all_users, user_list)
path
#> [1] "/path/to/all_users/user_1" "/path/to/all_users/user_2"

# Same but for paths prefer file.path()
devtools::load_all()
#> ℹ Loading pactaCore

parent <- path_home("pacta_tmp")
create_pacta(parent)

# results_path() detects a portfolio_pattern() in the input/ directory
portfolio_pattern()
#&gt; [1] "_Input[.]csv"
# A custom error with base
f <- function() {
  message <- paste(c("Oh no", "Messed up", "Need a hint?"), collapse = "\n")
  # Construct a custom class via `errorCondition()`
  stop(errorCondition(message, class = "my_error"))
}

# How it prints
f()