A portable configuration for the ‘lintr’ R package that includes a handful of custom linters that I commonly use.
This file contains 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
r6_class( | |
MyClass, | |
{ | |
initialize = function (x) { | |
private$x = x | |
} | |
get = function () private$x | |
}, | |
private = { |
This file contains 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
doc = function (...) { | |
doc = new.env(parent = emptyenv()) | |
doc$words = lapply(list(...), add_node, doc = doc) | |
doc | |
} | |
par = function (...) { | |
structure(list(...), class = c("par", "docnode")) | |
} |
This file contains 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
box::use( | |
dplyr[...], | |
glue[glue], | |
grid, | |
ld = lubridate, | |
ragg[...], | |
rvest, | |
scales[label_date_short, label_percent], | |
tidyr[...], | |
./screen_size[...], |
This file contains 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
test_cases_desc = R'( | |
Given the starting numbers 1,3,2, the 2020th number spoken is 1. | |
Given the starting numbers 2,1,3, the 2020th number spoken is 10. | |
Given the starting numbers 1,2,3, the 2020th number spoken is 27. | |
Given the starting numbers 2,3,1, the 2020th number spoken is 78. | |
Given the starting numbers 3,2,1, the 2020th number spoken is 438. | |
Given the starting numbers 3,1,2, the 2020th number spoken is 1836. | |
)' | |
`%>%` = magrittr::`%>%` |
This file contains 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
import pathlib | |
p = pathlib.Path('/foo') | |
print(f'p: "{p}", parent: "{p.parent}", root: "{p.root}"') | |
# p: "/foo", parent: "/", root: "/" | |
print(f'parent == root: {p.parent == p.root}') | |
# parent == root: False | |
print(f'parent.samefile(root): {p.parent.samefile(p.root)}') | |
# parent.samefile(root): True |
This file contains 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
alpha = numeric(1e4L) | |
beta = numeric(1e4L) | |
i = 0L | |
while (i < 1e4L) { | |
a = rnorm(1L, 10, 2) | |
b = rgamma(1L, 8, 1) | |
d = a - b | |
if (d < 1) { | |
i = i + 1L | |
alpha[i] = a |
This file contains 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
#include <algorithm> | |
#include <array> | |
#include <functional> | |
#include <random> | |
template <typename T = std::mt19937> | |
auto get_random_generator() -> T { | |
auto constexpr seed_bytes = sizeof(typename T::result_type) * T::state_size; | |
auto constexpr seed_len = seed_bytes / sizeof(std::seed_seq::result_type); | |
auto seed = std::array<std::seed_seq::result_type, seed_len>(); |
This file contains 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
auto read_file(std::string_view path) -> std::string { | |
constexpr auto read_size = std::size_t{4096}; | |
auto stream = std::ifstream{path.data()}; | |
stream.exceptions(std::ios_base::badbit); | |
auto out = std::string{}; | |
auto buf = std::string(read_size, '\0'); | |
while (stream.read(& buf[0], read_size)) { | |
out.append(buf, 0, stream.gcount()); | |
} |
NewerOlder