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
library(stringr) | |
# I had something like this | |
bobs <- c("bob.txt", "bob.scn", "bob") | |
# I want to remove just the strings with "scn" | |
# Using: https://stackoverflow.com/questions/5556213/regex-to-match-everything-except-the-given-words-which-may-include-hyphens-dash | |
str_subset(bobs, "^(?:(?!scn).)*$") | |
#> [1] "bob.txt" "bob" |
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
library(DBI) | |
library(dbplyr) | |
suppressPackageStartupMessages(library(dplyr)) | |
#> Warning: package 'dplyr' was built under R version 3.4.1 | |
options(tibble.width = Inf) | |
cn <- dbConnect(odbc::odbc(), dsn = "access-odbc") | |
#dbListTables(cn) |
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
library(DBI) | |
library(dbplyr) | |
library(dplyr, warn.conflicts = FALSE) | |
# This is an Access connection | |
cn <- dbConnect(odbc::odbc(), dsn = "dbplyr-testing") | |
# Connect to the test table | |
test_tbl <- tbl(cn, "test-1") |
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
db_write_table.ACCESS <- function(con, table, types, values, | |
temporary = FALSE, ...) { | |
db_create_table(con, table, types, temporary = temporary) | |
# Convert factors to strings | |
is_factor <- vapply(values, is.factor, logical(1)) | |
values[is_factor] <- lapply(values[is_factor], as.character) | |
# Encode special characters in strings |
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
library(rlang) | |
library(tibble, warn.conflicts = FALSE) | |
# A formula for the cars dataset | |
f <- as.formula("speed ~ dist") | |
f | |
#> speed ~ dist | |
#> <environment: 0x7f8399800d80> | |
# X |
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
# Just an example "vector of means" | |
vec_of_means <- c(6.4, 2, 3.3, 4.6, 5, 8) | |
n <- length(vec_of_means) | |
# Loops! | |
for(i in 1:(n-1)) { | |
print(paste0("Hello i: ", vec_of_means[i], " ===")) | |
for(j in (i+1):n) { |
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
# devtools::install_github("business-science/tibbletime") | |
library(tibbletime) | |
#> | |
#> Attaching package: 'tibbletime' | |
#> The following object is masked from 'package:stats': | |
#> | |
#> filter | |
library(tidyverse) | |
#> Loading tidyverse: ggplot2 | |
#> Loading tidyverse: tibble |
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
// [[Rcpp::depends(xtensor)]] | |
#include <numeric> | |
#include "xtensor/xmath.hpp" | |
#include "xtensor-r/rarray.hpp" | |
#include <Rcpp.h> | |
using namespace Rcpp; | |
// [[Rcpp::plugins(cpp14)]] |
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
suppressPackageStartupMessages(library(tibbletime)) | |
suppressPackageStartupMessages(library(tidyverse)) | |
data(FB) | |
# Create the column names | |
col_names <- map_chr(2:10, ~paste0("adjusted_", .x)) | |
# Creating the rolling functions and assign them names | |
rollers <- map(2:10, ~rollify(mean, window = .x)) %>% |
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
suppressPackageStartupMessages(library(tibbletime)) | |
suppressPackageStartupMessages(library(dplyr)) | |
suppressPackageStartupMessages(library(purrr)) | |
# Create a tibble of event dates, ~100k | |
# 2013-01-01 to the end of the year by 5 minutes | |
event_dates <- create_series(~2013, 5~M, force_class = "POSIXct") | |
event_dates | |
#> # A time tibble: 105,120 x 1 |
OlderNewer