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
#include <Rcpp.h> | |
using namespace Rcpp; | |
class BinFixed { | |
double width_; | |
double origin_; | |
public: |
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
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
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
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
// [[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
# Setup the build environment based on the specified dependencies. Returns an | |
# opaque object that can be passed to .restoreEnvironment to reverse whatever | |
# changes that were made | |
.setupBuildEnvironment <- function(depends) { | |
# discover dependencies | |
buildEnv <- list() | |
linkingToPackages <- c("Rcpp") | |
for (package in depends) { |
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
```{r engine='Rcpp'} | |
int fibonacci(const int x) { | |
if (x == 0) return(0); | |
if (x == 1) return(1); | |
return (fibonacci(x - 1)) + fibonacci(x - 2); | |
} | |
``` | |
```{r engine='Rcpp', Rcpp.plugin='RcppArmadillo'} | |
List fastLm(NumericVector yr, NumericMatrix Xr) { |
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::linking_to(RcppArmadillo)]] | |
#include <RcppArmadillo.h> | |
using namespace Rcpp; | |
// [[Rcpp::export]] | |
List fastLmCpp(NumericVector yr, NumericMatrix Xr) { | |
int n = Xr.nrow(), k = Xr.ncol(); |
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
#include <Rcpp.h> | |
using namespace Rcpp; | |
// [[Rcpp::export]] | |
int fibonacciCpp(const int x) { | |
if (x == 0) return(0); | |
if (x == 1) return(1); | |
NewerOlder