@@ -223,17 +223,17 @@ generate_r_functions <- function(funs, package = "cpp4r", use_package = FALSE) {
223223 }
224224
225225 funs $ package_call <- package_call
226-
226+
227227 # Extract default values and create parameter lists
228228 funs $ param_info <- lapply(funs $ args , function (args_df ) {
229229 if (nrow(args_df ) == 0 ) {
230230 return (list (params = " " , args = " " , checks = " " ))
231231 }
232-
232+
233233 # Parse default values from the type column (they appear after '=')
234234 param_names <- args_df $ name
235235 param_types <- args_df $ type
236-
236+
237237 # Extract defaults (format: "type name = value" becomes "value")
238238 defaults <- vapply(param_types , function (t ) {
239239 if (grepl(" =" , t )) {
@@ -242,12 +242,12 @@ generate_r_functions <- function(funs, package = "cpp4r", use_package = FALSE) {
242242 " "
243243 }
244244 }, character (1 ))
245-
245+
246246 # Clean up types (remove default value parts)
247247 clean_types <- vapply(param_types , function (t ) {
248248 trimws(sub(" \\ s*=.*$" , " " , t ))
249249 }, character (1 ))
250-
250+
251251 # Generate R function parameters with defaults
252252 params_with_defaults <- vapply(seq_along(param_names ), function (i ) {
253253 if (nzchar(defaults [i ])) {
@@ -258,24 +258,24 @@ generate_r_functions <- function(funs, package = "cpp4r", use_package = FALSE) {
258258 param_names [i ]
259259 }
260260 }, character (1 ))
261-
261+
262262 # Generate type checking/coercion code
263263 checks <- vapply(seq_along(param_names ), function (i ) {
264264 generate_type_check(param_names [i ], clean_types [i ])
265265 }, character (1 ))
266266 checks <- checks [nzchar(checks )]
267-
267+
268268 list (
269269 params = paste(params_with_defaults , collapse = " , " ),
270270 args = paste(param_names , collapse = " , " ),
271271 checks = if (length(checks ) > 0 ) paste0(" \t " , checks , collapse = " \n " ) else " "
272272 )
273273 })
274-
274+
275275 funs $ list_params <- vapply(funs $ param_info , function (x ) x $ params , character (1 ))
276276 funs $ call_args <- vapply(funs $ param_info , function (x ) x $ args , character (1 ))
277277 funs $ type_checks <- vapply(funs $ param_info , function (x ) x $ checks , character (1 ))
278-
278+
279279 funs $ params <- vcapply(funs $ call_args , function (x ) if (nzchar(x )) paste0(" , " , x ) else x )
280280 is_void <- funs $ return_type == " void"
281281 funs $ calls <- ifelse(is_void ,
@@ -308,7 +308,7 @@ generate_r_functions <- function(funs, package = "cpp4r", use_package = FALSE) {
308308 } else {
309309 paste0(" \n\t " , calls , " \n " )
310310 }
311-
311+
312312 if (nzchar(roxygen_comment )) {
313313 glue :: glue(" {roxygen_comment}\n {name} <- function({list_params}) {{{body}}}" )
314314 } else {
@@ -324,7 +324,7 @@ generate_r_functions <- function(funs, package = "cpp4r", use_package = FALSE) {
324324# Helper function to convert C++ default values to R
325325convert_cpp_default_to_r <- function (cpp_default ) {
326326 cpp_default <- trimws(cpp_default )
327-
327+
328328 # Handle common cases
329329 if (cpp_default == " true" || cpp_default == " TRUE" ) {
330330 return (" TRUE" )
@@ -342,7 +342,7 @@ convert_cpp_default_to_r <- function(cpp_default) {
342342 } else if (cpp_default == " NULL" || cpp_default == " nullptr" ) {
343343 return (" NULL" )
344344 }
345-
345+
346346 # Default: keep as-is and hope for the best
347347 cpp_default
348348}
0 commit comments