Skip to content

Instantly share code, notes, and snippets.

View knapply's full-sized avatar
🕵️

knapply

🕵️
View GitHub Profile
import requests
import csv
import datetime
import calendar
import time
i=0
# Change the range depending on how long you like to record the data
for i in range (0,50):
@nacnudus
nacnudus / rcpp-na-vs-std-vector.R
Created September 15, 2017 17:26
Rcpp NA values vs std::vector<something>
# Rcpp NAs vs std::vector
library(Rcpp)
cppFunction("
List test1() {
return List::create(
NumericVector::create(NA_REAL),
IntegerVector::create(NA_INTEGER),
LogicalVector::create(NA_LOGICAL),
CharacterVector::create(NA_STRING));
@hrbrmstr
hrbrmstr / Readme.md
Created January 26, 2017 11:50 — forked from timelyportfolio/Readme.md
igraph layout editing with mapedit

This is certainly not the intended purpose of mapedit, but I thought it would be fun to use some accumulated R knowledge to use mapedit and leaflet to edit an igraph layout. To run the code, make sure to run the edit_map and Shiny parts separately.

library(igraph)
library(leaflet)
library(mapedit)

karate <- graph.famous("Zachary")
igrf_layout <- layout.auto(karate)
@jcheng5
jcheng5 / withConsoleRedirect.R
Created June 29, 2016 05:05
Someone at #useR2016 asked me if you can have Shiny execute code in observers/reactives but send the console output to the browser.
library(shiny)
withConsoleRedirect <- function(containerId, expr) {
# Change type="output" to type="message" to catch stderr
# (messages, warnings, and errors) instead of stdout.
txt <- capture.output(results <- expr, type = "output")
if (length(txt) > 0) {
insertUI(paste0("#", containerId), where = "beforeEnd",
ui = paste0(txt, "\n", collapse = "")
)
@romainfrancois
romainfrancois / gist:7117691
Last active April 12, 2020 17:22
create list with more than 20 elements (different syntax)
#include <Rcpp.h>
using namespace Rcpp ;
template <typename T>
inline void set_item_impl( List& target, int i, const T& obj, CharacterVector& names, traits::true_type ){
target[i] = obj.object ;
names[i] = obj.name ;
}
template <typename T>
@romainfrancois
romainfrancois / biglist.cpp
Created October 23, 2013 12:15
create lists with more than 20 elements
#include <Rcpp.h>
using namespace Rcpp ;
template <typename T>
inline void set_item_impl( List& target, int i, const T& obj, CharacterVector& names, traits::true_type ){
target[i] = obj.object ;
names[i] = obj.name ;
}
template <typename T>