Skip to content

Instantly share code, notes, and snippets.

View carlganz's full-sized avatar

Carl Ganz carlganz

View GitHub Profile
@carlganz
carlganz / build.rs
Last active August 18, 2020 07:16
R bindgen
extern crate bindgen;
use std::env;
use std::path::PathBuf;
fn main() {
println!("cargo:rustc-link-lib=R");
println!("cargo:rustc-link-search=native={}", "/usr/lib/R/lib");
// The bindgen::Builder is the main entry point
// to bindgen, and lets you build up options for
@carlganz
carlganz / installOldPackages.R
Last active April 8, 2019 17:23
If you are upgrading from R 3.2 to R 3.3 you have to go to the hassle of redownloading all your packages. This code will try to download all your old packages.
# get library path
lib <- .libPaths()[1]
# does it end in 3.3?
if (grepl("*3.3",lib)) {
# if yes then assume old library is same place with 3.2 instead
oldlib <- gsub("*3.3","3.2",lib)
}
# check that old library exists
library(dplyr)
library(survey)
data(nhanes)
# with clusters
svy <- svydesign(id=~SDMVPSU, strata=~SDMVSTRA, weights=~WTMEC2YR, nest=TRUE, data=nhanes)
svytotal(~HI_CHOL, svy, na.rm = TRUE)
### reproducing results with dplyr is simple
nhanes %>%
@carlganz
carlganz / code.R
Created November 14, 2017 19:46
How to make list-cols?
library(dplyr)
library(tibble)
myList <- list(
list(
id = 1,
name = "A",
sublist = list(
a=1,b=2
)
@carlganz
carlganz / app.R
Created October 9, 2017 00:52 — forked from jcheng5/app.R
Using OAuth2 with Shiny
library(shiny)
# WARNING: This sketch does not make proper use of the "state" parameter.
# Doing so usually involves using cookies, which can be done with the
# Rook package but I have not done that here. If you choose to use this
# approach in production, please check the state parameter properly!
APP_URL <- if (interactive()) {
# This might be useful for local development. If not, just hardcode APP_URL
# to the deployed URL that you'll provide a few lines below.
@carlganz
carlganz / R
Created January 13, 2017 00:35
Lumley Blog Post
setMethod("%*%", c("gammaconv","gammaconv"), function(x,y) {
# maxterms<-sum(outer(x@power,y@power,function(n1,n2) 2*pmax(n1+1,n2+1)))
allcoef<- list() #numeric(maxterms)
allpower<- list() #integer(maxterms)
allexp<- list() #numeric(maxterms)
# here<-0
iterator <- 1
test <- function() {
ui <- miniPage(
gadgetTitleBar("Test"),
miniContentPanel(
uiOutput("test")
)
)
server <- function(input,output,session) {