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(RcppArmadillo)]] | |
#include <Rcpp.h> | |
#include <RcppArmadillo.h> | |
using namespace Rcpp; |
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
IntegerVector table1(const CharacterVector x) { | |
std::map<char*, int> counts; | |
int n = x.length(); | |
for (int i = 0; i < n; i++) { | |
counts[x[i]]++; | |
} | |
// Loop through each element of map and output into named vector | |
IntegerVector out(counts.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
library(Rcpp) | |
library(microbenchmark) | |
cppFunction(' | |
IntegerVector table1(const CharacterVector x) { | |
std::map<std::string, int> counts; | |
std::vector<std::string> vec = as<std::vector<std::string> >(x); | |
int n = x.length(); | |
for (int i = 0; i < n; i++) { |
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
loadedPackageUpdateRequired <- function(pkgs) { | |
if (any(pkgs %in% loadedNamespaces())) { | |
return(TRUE) | |
} | |
else { | |
# compute dependent packages | |
avail <- available.packages() | |
if (getRversion() >= "2.15") | |
deps <- tools:::package_dependencies(pkgs, db = avail, recursive = 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
loadedPackageRequiresUpdate <- function(pkgs) { | |
if (any(pkgs %in% loadedNamespaces())) { | |
return(TRUE) | |
} | |
else { | |
# compute dependent packages | |
avail <- available.packages() | |
if (getRversion() >= "2.15") | |
deps <- tools:::package_dependencies(pkgs, db = avail, recursive = TRUE) | |
else |
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(shiny) | |
library(datasets) | |
# Define server logic required to summarize and view the selected dataset | |
shinyServer(function(input, output) { | |
# Return the requested dataset | |
datasetInput <- reactive({ | |
switch(input$dataset, | |
"rock" = rock, |
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(shiny) | |
library(datasets) | |
# Define server logic required to summarize and view the selected dataset | |
shinyServer(function(input, output) { | |
# By declaring databaseInput as a reactive expression we ensure that: | |
# | |
# 1) It is only called when the inputs it depends on changes | |
# 2) The computation and result are shared by all the callers (it |
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(shiny) | |
library(datasets) | |
# We tweak the "am" field to have nicer factor labels. Since this doesn't | |
# rely on any user inputs we can do this once at startup and then use the | |
# value throughout the lifetime of the application | |
mpgData <- mtcars | |
mpgData$am <- factor(mpgData$am, labels = c("Automatic", "Manual")) | |
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(shiny) | |
# Define server logic for slider examples | |
shinyServer(function(input, output) { | |
# Reactive expression to compose a data frame containing all of the values | |
sliderValues <- reactive({ | |
# Compose data frame | |
data.frame( |
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(shiny) | |
library(datasets) | |
# Define server logic required to summarize and view the selected dataset | |
shinyServer(function(input, output) { | |
# Return the requested dataset | |
datasetInput <- reactive({ | |
switch(input$dataset, | |
"rock" = rock, |