67
67
# ' @export
68
68
cpp_source <- function (file , code = NULL , env = parent.frame(), clean = TRUE , quiet = TRUE , cxx_std = Sys.getenv(" CXX_STD" , " CXX11" ), dir = tempfile()) {
69
69
stop_unless_installed(c(" brio" , " callr" , " cli" , " decor" , " desc" , " glue" , " tibble" , " vctrs" ))
70
- if (! missing(file ) && ! file.exists(file )) {
71
- stop(" Can't find `file` at this path:\n " , file , " \n " , call. = FALSE )
70
+ if (! missing(file ) && ! all( file.exists(file ) )) {
71
+ stop(" Can't find `file` at this path:\n " , file [ ! file.exists( file )][[ 1 ]] , " \n " , call. = FALSE )
72
72
}
73
73
74
74
dir.create(dir , showWarnings = FALSE , recursive = TRUE )
@@ -87,8 +87,8 @@ cpp_source <- function(file, code = NULL, env = parent.frame(), clean = TRUE, qu
87
87
stop(" `file` must have a `.cpp` or `.cc` extension" )
88
88
}
89
89
90
- name <- generate_cpp_name (file )
91
- package <- tools :: file_path_sans_ext(name )
90
+ name <- vapply (file , generate_cpp_name , character ( 1 ) )
91
+ package <- tools :: file_path_sans_ext(name [[ 1 ]] )
92
92
93
93
orig_dir <- normalizePath(dirname(file ), winslash = " /" )
94
94
new_dir <- normalizePath(file.path(dir , " src" ), winslash = " /" )
@@ -112,7 +112,7 @@ cpp_source <- function(file, code = NULL, env = parent.frame(), clean = TRUE, qu
112
112
funs <- get_registered_functions(all_decorations , " cpp11::register" , quiet = quiet )
113
113
cpp_functions_definitions <- generate_cpp_functions(funs , package = package )
114
114
115
- cpp_path <- file.path(dirname(new_file_path ), " cpp11.cpp" )
115
+ cpp_path <- file.path(dirname(new_file_path [[ 1 ]] ), " cpp11.cpp" )
116
116
brio :: write_lines(c(' #include "cpp11/declarations.hpp"' , " using namespace ::cpp11;" , cpp_functions_definitions ), cpp_path )
117
117
118
118
linking_to <- union(get_linking_to(all_decorations ), " cpp11" )
@@ -140,7 +140,7 @@ cpp_source <- function(file, code = NULL, env = parent.frame(), clean = TRUE, qu
140
140
stop(" Compilation failed." , call. = FALSE )
141
141
}
142
142
143
- shared_lib <- file.path(dir , " src" , paste0(tools :: file_path_sans_ext( new_file_name ) , .Platform $ dynlib.ext ))
143
+ shared_lib <- file.path(dir , " src" , paste0(package , .Platform $ dynlib.ext ))
144
144
r_path <- file.path(dir , " R" , " cpp11.R" )
145
145
brio :: write_lines(r_functions , r_path )
146
146
source(r_path , local = env )
0 commit comments