1212# ' **you**. Bugfixes and new features in cpp11 will not be available for your
1313# ' code until you run `cpp_vendor()` again.
1414# '
15- # ' @param path The path to vendor the code into.
15+ # ' @param dir The directoyy to vendor the code into.
16+ # ' @param subdir The subdirectory to vendor the code into.
1617# ' @return The file path to the vendored code (invisibly).
1718# ' @export
1819# ' @examples
2728# '
2829# ' # cleanup
2930# ' unlink(dir, recursive = TRUE)
30- cpp_vendor <- function (path = NULL ) {
31- if (is.null(path )) {
31+ cpp_vendor <- function (dir = NULL , subdir = " /inst/include " ) {
32+ if (is.null(dir )) {
3233 stop(" You must provide a path to vendor the code into" , call. = FALSE )
33- } else {
34- path <- paste0(path , " /inst/include" )
3534 }
36-
37- new <- file.path(path )
3835
39- if (dir.exists(new )) {
40- stop(" '" , new , " ' already exists\n * run unlink('" , new , " ', recursive = TRUE)" , call. = FALSE )
36+ path <- paste0(dir , subdir )
37+
38+ path2 <- file.path(path , " cpp11" )
39+ if (dir.exists(path2 )) {
40+ stop(" '" , path2 , " ' already exists\n * run unlink('" , path2 , " ', recursive = TRUE)" , call. = FALSE )
4141 }
4242
4343 # Vendor cpp11 ----
4444
45- dir.create(new , recursive = TRUE , showWarnings = FALSE )
46- dir.create(file.path(new , " cpp11" ), recursive = TRUE , showWarnings = FALSE )
45+ dir.create(
46+ path2 ,
47+ recursive = TRUE ,
48+ showWarnings = FALSE
49+ )
4750
48- current <- system.file(" include" , " cpp11" , package = " cpp11" )
51+ current_cpp11 <- system.file(
52+ " include" ,
53+ " cpp11" ,
54+ package = " cpp11"
55+ )
4956
50- if (! nzchar(current )) {
57+ if (! nzchar(current_cpp11 )) {
5158 stop(" cpp11 is not installed" , call. = FALSE )
5259 }
5360
5461 cpp11_version <- utils :: packageVersion(" cpp11" )
5562
56- cpp11_header <- sprintf(" // cpp11 version: %s\n // vendored on: %s" , cpp11_version , Sys.Date())
57-
58- main_header <- list.files(current , pattern = " \\ .hpp$" , full.names = TRUE )
59- headers <- list.files(file.path(current , " cpp11" ), pattern = " \\ .hpp$" , full.names = TRUE )
63+ cpp11_header <- sprintf(
64+ " // cpp11 version: %s\n // vendored on: %s" ,
65+ cpp11_version ,
66+ Sys.Date()
67+ )
6068
61- writeLines(c(cpp11_header , readLines(main_header )), file.path(new , basename(main_header )))
69+ write_header(
70+ path , " cpp11.hpp" , " cpp11" ,
71+ cpp11_header
72+ )
6273
63- for (h in headers ) {
64- writeLines(c(cpp11_header , readLines(h )), file.path(new , " cpp11" , basename(h )))
65- }
74+ copy_files(
75+ list.files(current_cpp11 , full.names = TRUE ),
76+ path , " cpp11" , cpp11_header
77+ )
6678
6779 # Additional steps to make vendoring work ----
6880
@@ -73,23 +85,25 @@ cpp_vendor <- function(path = NULL) {
7385
7486 message(" DESCRIPTION should not have lines such as 'LinkingTo: cpp11'" )
7587
76- invisible (new )
88+ invisible (path )
7789}
7890
79- write_header <- function (path , header , pkg , cpp11_header ) {
91+ write_header <- function (path , header , pkg , cpp11armadillo_header ) {
8092 writeLines(
8193 c(
82- cpp11_header ,
83- readLines(system.file(" include" , header , package = pkg ))
94+ cpp11armadillo_header ,
95+ readLines(
96+ system.file(" include" , header , package = pkg )
97+ )
8498 ),
8599 file.path(path , header )
86100 )
87101}
88102
89- copy_files <- function (files , path , out , cpp11_header ) {
103+ copy_files <- function (files , path , out , cpp11armadillo_header ) {
90104 for (f in files ) {
91105 writeLines(
92- c(cpp11_header , readLines(f )),
106+ c(cpp11armadillo_header , readLines(f )),
93107 file.path(path , out , basename(f ))
94108 )
95109 }
0 commit comments