Skip to content

Instantly share code, notes, and snippets.

@trestletech
Created December 16, 2019 22:41
Show Gist options
  • Save trestletech/d07fa170b613c5c0107ef000a15ef72e to your computer and use it in GitHub Desktop.
Save trestletech/d07fa170b613c5c0107ef000a15ef72e to your computer and use it in GitHub Desktop.
Rcpp data.frame issue
---
title: "Rcpp Dataframe issue"
output: github_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
fun <- Rcpp::cppFunction('
List DataFrameExample() {
Rcpp::IntegerVector a = {1, 2, 3};
// create a new data frame
Rcpp::DataFrame DF = Rcpp::DataFrame::create(
Rcpp::Named("a1")=a
);
Rcpp::DataFrame NDF = clone(DF);
//NDF.push_back(a, "a2");
NDF["a2"] = a;
return(Rcpp::List::create(
Rcpp::Named("origDataFrame")=DF,
Rcpp::Named("newDataFrame")=NDF)
);
}')
dfs <- fun()
dfs
lapply(dfs, class)
lapply(dfs, attributes)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment