├── _pkgdown.yml ├── src ├── code.o ├── RcppExports.o ├── RcppCopyExample.so ├── code.cpp └── RcppExports.cpp ├── NAMESPACE ├── .Rbuildignore ├── .gitignore ├── man └── RcppCopyExample-package.Rd ├── RcppCopyExample.Rproj ├── DESCRIPTION ├── R └── RcppExports.R ├── vignettes └── RcppRef.Rmd └── .github └── workflows └── pkgdown.yml /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | destination: docs -------------------------------------------------------------------------------- /src/code.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DominikRafacz/RcppCopyExample/master/src/code.o -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | useDynLib(RcppCopyExample, .registration=TRUE) 2 | importFrom(Rcpp, evalCpp) 3 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^_pkgdown\.yml$ 4 | ^docs$ 5 | ^pkgdown$ 6 | -------------------------------------------------------------------------------- /src/RcppExports.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DominikRafacz/RcppCopyExample/master/src/RcppExports.o -------------------------------------------------------------------------------- /src/RcppCopyExample.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DominikRafacz/RcppCopyExample/master/src/RcppCopyExample.so -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | inst/doc 2 | .Rproj.user 3 | docs 4 | src/*.o 5 | src/*.so 6 | src/*.dll 7 | .Rproj.user 8 | src/*.o 9 | src/*.dll 10 | .Rproj.user/* 11 | inst/doc 12 | src-i386/* 13 | src-x64/* 14 | .idea/* 15 | cmake-build-debug/* -------------------------------------------------------------------------------- /man/RcppCopyExample-package.Rd: -------------------------------------------------------------------------------- 1 | \name{RcppCopyExample-package} 2 | \alias{RcppCopyExample-package} 3 | \alias{RcppCopyExample} 4 | \docType{package} 5 | \title{\packageTitle{RcppCopyExample}} 6 | \description{\packageDescription{RcppCopyExample}} 7 | \section{Package Content}{\packageIndices{RcppCopyExample}} 8 | \author{\packageAuthor{RcppCopyExample}} 9 | \section{Maintainer}{\packageMaintainer{RcppCopyExample}} 10 | \keyword{package} 11 | -------------------------------------------------------------------------------- /RcppCopyExample.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Package 16 | PackageUseDevtools: Yes 17 | PackageInstallArgs: --no-multiarch --with-keep.source 18 | PackageRoxygenize: rd,collate,namespace,vignette 19 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: RcppCopyExample 2 | Type: Package 3 | Title: What the Package Does in One 'Title Case' Line 4 | Version: 1.0 5 | Date: 2020-07-15 6 | Author: Dominik Rafacz 7 | Maintainer: Dominik Rafacz 8 | Description: One paragraph description of what the package does as one or more full 9 | sentences. 10 | License: GPL (>= 2) 11 | Imports: Rcpp (>= 1.0.4) 12 | LinkingTo: Rcpp 13 | Roxygen: list(markdown = TRUE) 14 | RoxygenNote: 7.1.0 15 | Suggests: 16 | knitr, 17 | rmarkdown 18 | VignetteBuilder: knitr 19 | -------------------------------------------------------------------------------- /R/RcppExports.R: -------------------------------------------------------------------------------- 1 | # Generated by using Rcpp::compileAttributes() -> do not edit by hand 2 | # Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 3 | 4 | #' @export 5 | do_sth <- function(some_vector) { 6 | .Call(`_RcppCopyExample_do_sth`, some_vector) 7 | } 8 | 9 | #' @export 10 | do_sth_more <- function(some_list) { 11 | .Call(`_RcppCopyExample_do_sth_more`, some_list) 12 | } 13 | 14 | #' @export 15 | create_vector_list_with_one_modification <- function(v) { 16 | .Call(`_RcppCopyExample_create_vector_list_with_one_modification`, v) 17 | } 18 | 19 | #' @export 20 | create_vector_list_with_two_modifications <- function(v) { 21 | .Call(`_RcppCopyExample_create_vector_list_with_two_modifications`, v) 22 | } 23 | 24 | #' @export 25 | add_attr <- function(v) { 26 | .Call(`_RcppCopyExample_add_attr`, v) 27 | } 28 | 29 | -------------------------------------------------------------------------------- /vignettes/RcppRef.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Rcpp Doesn't Copy (At Least Sometimes)" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Rcpp Doesn't Copy (At Least Sometimes)} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | ```{r, include = FALSE} 11 | knitr::opts_chunk$set( 12 | collapse = TRUE, 13 | comment = "#>" 14 | ) 15 | ``` 16 | 17 | ```{r setup} 18 | library(RcppCopyExample) 19 | ``` 20 | 21 | 22 | ```{r} 23 | # copy 24 | a <- c(1, 2, 3) 25 | a 26 | RcppCopyExample:::do_sth(a) 27 | a 28 | 29 | # no copy 30 | b <- list(1, 2, 3) 31 | b 32 | RcppCopyExample:::do_sth_more(b) 33 | b 34 | 35 | # multiple 36 | x <- c(0, 0, 0) 37 | RcppCopyExample::create_vector_list_with_one_modification(x) 38 | x 39 | 40 | #even more multiple 41 | x <- c(0, 0, 0) 42 | RcppCopyExample::create_vector_list_with_two_modifications(x) 43 | x 44 | 45 | # add attributes 46 | x <- c(1,2,3) 47 | x 48 | RcppCopyExample::add_attr(x) 49 | x 50 | ``` -------------------------------------------------------------------------------- /src/code.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace Rcpp; 4 | 5 | //' @export 6 | //[[Rcpp::export]] 7 | IntegerVector do_sth(IntegerVector some_vector) { 8 | some_vector[0] = 12345; 9 | return some_vector; 10 | } 11 | 12 | //' @export 13 | //[[Rcpp::export]] 14 | List do_sth_more(List some_list) { 15 | some_list[0] = IntegerVector(10); 16 | return some_list; 17 | } 18 | 19 | //' @export 20 | // [[Rcpp::export]] 21 | List create_vector_list_with_one_modification(IntegerVector v) { 22 | auto a = v; 23 | auto b = v; 24 | 25 | a[1] = 123; 26 | 27 | return List::create(a, b, v); 28 | } 29 | 30 | //' @export 31 | // [[Rcpp::export]] 32 | List create_vector_list_with_two_modifications(IntegerVector v) { 33 | auto a = v; 34 | auto b = v; 35 | 36 | a[1] = 123; 37 | b[1] = 202; 38 | 39 | return List::create(a, b, v); 40 | } 41 | 42 | //' @export 43 | // [[Rcpp::export]] 44 | IntegerVector add_attr(IntegerVector v) { 45 | v.attr("aa") = 1; 46 | 47 | return v; 48 | } 49 | -------------------------------------------------------------------------------- /.github/workflows/pkgdown.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: master 4 | 5 | name: pkgdown 6 | 7 | jobs: 8 | pkgdown: 9 | runs-on: macOS-latest 10 | env: 11 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 12 | steps: 13 | - uses: actions/checkout@v2 14 | 15 | - uses: r-lib/actions/setup-r@master 16 | 17 | - uses: r-lib/actions/setup-pandoc@master 18 | 19 | - name: Query dependencies 20 | run: | 21 | install.packages('remotes') 22 | saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) 23 | writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") 24 | shell: Rscript {0} 25 | 26 | - name: Cache R packages 27 | uses: actions/cache@v1 28 | with: 29 | path: ${{ env.R_LIBS_USER }} 30 | key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} 31 | restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- 32 | 33 | - name: Install dependencies 34 | run: | 35 | install.packages("remotes") 36 | remotes::install_deps(dependencies = TRUE) 37 | remotes::install_dev("pkgdown") 38 | shell: Rscript {0} 39 | 40 | - name: Install package 41 | run: R CMD INSTALL . 42 | 43 | - name: Deploy package 44 | run: pkgdown::deploy_to_branch(new_process = FALSE) 45 | shell: Rscript {0} 46 | 47 | -------------------------------------------------------------------------------- /src/RcppExports.cpp: -------------------------------------------------------------------------------- 1 | // Generated by using Rcpp::compileAttributes() -> do not edit by hand 2 | // Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 3 | 4 | #include 5 | 6 | using namespace Rcpp; 7 | 8 | // do_sth 9 | IntegerVector do_sth(IntegerVector some_vector); 10 | RcppExport SEXP _RcppCopyExample_do_sth(SEXP some_vectorSEXP) { 11 | BEGIN_RCPP 12 | Rcpp::RObject rcpp_result_gen; 13 | Rcpp::RNGScope rcpp_rngScope_gen; 14 | Rcpp::traits::input_parameter< IntegerVector >::type some_vector(some_vectorSEXP); 15 | rcpp_result_gen = Rcpp::wrap(do_sth(some_vector)); 16 | return rcpp_result_gen; 17 | END_RCPP 18 | } 19 | // do_sth_more 20 | List do_sth_more(List some_list); 21 | RcppExport SEXP _RcppCopyExample_do_sth_more(SEXP some_listSEXP) { 22 | BEGIN_RCPP 23 | Rcpp::RObject rcpp_result_gen; 24 | Rcpp::RNGScope rcpp_rngScope_gen; 25 | Rcpp::traits::input_parameter< List >::type some_list(some_listSEXP); 26 | rcpp_result_gen = Rcpp::wrap(do_sth_more(some_list)); 27 | return rcpp_result_gen; 28 | END_RCPP 29 | } 30 | // create_vector_list_with_one_modification 31 | List create_vector_list_with_one_modification(IntegerVector v); 32 | RcppExport SEXP _RcppCopyExample_create_vector_list_with_one_modification(SEXP vSEXP) { 33 | BEGIN_RCPP 34 | Rcpp::RObject rcpp_result_gen; 35 | Rcpp::RNGScope rcpp_rngScope_gen; 36 | Rcpp::traits::input_parameter< IntegerVector >::type v(vSEXP); 37 | rcpp_result_gen = Rcpp::wrap(create_vector_list_with_one_modification(v)); 38 | return rcpp_result_gen; 39 | END_RCPP 40 | } 41 | // create_vector_list_with_two_modifications 42 | List create_vector_list_with_two_modifications(IntegerVector v); 43 | RcppExport SEXP _RcppCopyExample_create_vector_list_with_two_modifications(SEXP vSEXP) { 44 | BEGIN_RCPP 45 | Rcpp::RObject rcpp_result_gen; 46 | Rcpp::RNGScope rcpp_rngScope_gen; 47 | Rcpp::traits::input_parameter< IntegerVector >::type v(vSEXP); 48 | rcpp_result_gen = Rcpp::wrap(create_vector_list_with_two_modifications(v)); 49 | return rcpp_result_gen; 50 | END_RCPP 51 | } 52 | // add_attr 53 | IntegerVector add_attr(IntegerVector v); 54 | RcppExport SEXP _RcppCopyExample_add_attr(SEXP vSEXP) { 55 | BEGIN_RCPP 56 | Rcpp::RObject rcpp_result_gen; 57 | Rcpp::RNGScope rcpp_rngScope_gen; 58 | Rcpp::traits::input_parameter< IntegerVector >::type v(vSEXP); 59 | rcpp_result_gen = Rcpp::wrap(add_attr(v)); 60 | return rcpp_result_gen; 61 | END_RCPP 62 | } 63 | 64 | static const R_CallMethodDef CallEntries[] = { 65 | {"_RcppCopyExample_do_sth", (DL_FUNC) &_RcppCopyExample_do_sth, 1}, 66 | {"_RcppCopyExample_do_sth_more", (DL_FUNC) &_RcppCopyExample_do_sth_more, 1}, 67 | {"_RcppCopyExample_create_vector_list_with_one_modification", (DL_FUNC) &_RcppCopyExample_create_vector_list_with_one_modification, 1}, 68 | {"_RcppCopyExample_create_vector_list_with_two_modifications", (DL_FUNC) &_RcppCopyExample_create_vector_list_with_two_modifications, 1}, 69 | {"_RcppCopyExample_add_attr", (DL_FUNC) &_RcppCopyExample_add_attr, 1}, 70 | {NULL, NULL, 0} 71 | }; 72 | 73 | RcppExport void R_init_RcppCopyExample(DllInfo *dll) { 74 | R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); 75 | R_useDynamicSymbols(dll, FALSE); 76 | } 77 | --------------------------------------------------------------------------------