6767# ' @export
6868cpp_source <- function (file , code = NULL , env = parent.frame(), clean = TRUE , quiet = TRUE , cxx_std = Sys.getenv(" CXX_STD" , " CXX11" ), dir = tempfile()) {
6969 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 )
7272 }
7373
7474 dir.create(dir , showWarnings = FALSE , recursive = TRUE )
@@ -87,8 +87,8 @@ cpp_source <- function(file, code = NULL, env = parent.frame(), clean = TRUE, qu
8787 stop(" `file` must have a `.cpp` or `.cc` extension" )
8888 }
8989
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 ]] )
9292
9393 orig_dir <- normalizePath(dirname(file ), winslash = " /" )
9494 new_dir <- normalizePath(file.path(dir , " src" ), winslash = " /" )
@@ -112,7 +112,7 @@ cpp_source <- function(file, code = NULL, env = parent.frame(), clean = TRUE, qu
112112 funs <- get_registered_functions(all_decorations , " cpp11::register" , quiet = quiet )
113113 cpp_functions_definitions <- generate_cpp_functions(funs , package = package )
114114
115- cpp_path <- file.path(dirname(new_file_path ), " cpp11.cpp" )
115+ cpp_path <- file.path(dirname(new_file_path [[ 1 ]] ), " cpp11.cpp" )
116116 brio :: write_lines(c(' #include "cpp11/declarations.hpp"' , " using namespace ::cpp11;" , cpp_functions_definitions ), cpp_path )
117117
118118 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
140140 stop(" Compilation failed." , call. = FALSE )
141141 }
142142
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 ))
144144 r_path <- file.path(dir , " R" , " cpp11.R" )
145145 brio :: write_lines(r_functions , r_path )
146146 source(r_path , local = env )
0 commit comments