Skip to content

Instantly share code, notes, and snippets.

View DavisVaughan's full-sized avatar

Davis Vaughan DavisVaughan

View GitHub Profile
@DavisVaughan
DavisVaughan / odbc-access-testing.r
Last active July 7, 2017 14:21
odbc-access-testing
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)
library(rlang)
library(tibble, warn.conflicts = FALSE)
# A formula for the cars dataset
f <- as.formula("speed ~ dist")
f
#> speed ~ dist
#> <environment: 0x7f8399800d80>
# X
# 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) {
# 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
// [[Rcpp::depends(xtensor)]]
#include <numeric>
#include "xtensor/xmath.hpp"
#include "xtensor-r/rarray.hpp"
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::plugins(cpp14)]]
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
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
``` r
library(odbc)
#> Warning: package 'odbc' was built under R version 3.4.2
library(DBI)
con <- DBI::dbConnect(odbc::odbc(),
Driver = "PostgreSQL ODBC Driver(ANSI)",
Server = "localhost",
Database = "postgres",
UID = 'postgres',
``` r
library(tibbletime)
library(dplyr)
options(digits.secs = 6)
# 1000 values
ex <- create_series('2013' ~ '2013-01-01 00:00:00.999', period = "1 millisec")
# Random data
library(tibbletime)
library(dplyr)
library(zoo)
data(FB)
window <- 6
rolling_mean <- rollify(mean, window = window)
FB_roll <- FB %>%