Skip to content

Commit

Permalink
consider the case where a file does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
pachadotdev committed Jan 4, 2025
1 parent 7a436d6 commit a781c99
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions R/register.R
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ generate_r_functions <- function(funs, package = "cpp11", use_package = FALSE) {
package_call <- glue::glue(', PACKAGE = "{package}"')
package_names <- glue::glue_data(funs, '"_{package}_{name}"')
} else {
package_names <- glue::glue_data(funs, '`_{package}_{name}`')
package_names <- glue::glue_data(funs, "`_{package}_{name}`")
package_call <- ""
}

Expand All @@ -229,22 +229,26 @@ generate_r_functions <- function(funs, package = "cpp11", use_package = FALSE) {
funs$params <- vcapply(funs$list_params, function(x) if (nzchar(x)) paste0(", ", x) else x)
is_void <- funs$return_type == "void"
funs$calls <- ifelse(is_void,
glue::glue_data(funs, 'invisible(.Call({package_names}{params}{package_call}))'),
glue::glue_data(funs, '.Call({package_names}{params}{package_call})')
glue::glue_data(funs, "invisible(.Call({package_names}{params}{package_call}))"),
glue::glue_data(funs, ".Call({package_names}{params}{package_call})")
)

# Parse and associate Roxygen comments
funs$roxygen_comment <- mapply(function(file, line) {
comments <- extract_roxygen_comments(file)
matched_comment <- ""
for (comment in comments) {
# Check if the comment directly precedes the function without gaps
if (line == comment$line + 1) {
matched_comment <- comment$text
break
if (file.exists(file)) {
comments <- extract_roxygen_comments(file)
matched_comment <- ""
for (comment in comments) {
# Check if the comment directly precedes the function without gaps
if (line == comment$line + 1) {
matched_comment <- comment$text
break

Check warning on line 245 in R/register.R

View check run for this annotation

Codecov / codecov/patch

R/register.R#L243-L245

Added lines #L243 - L245 were not covered by tests
}
}
matched_comment
} else {
""
}
matched_comment
}, funs$file, funs$line, SIMPLIFY = TRUE)

# Generate R functions with or without Roxygen comments
Expand All @@ -254,9 +258,8 @@ generate_r_functions <- function(funs, package = "cpp11", use_package = FALSE) {
} else {
glue::glue("{name} <- function({list_params}) {{\n {calls}\n}}")
}
}, funs$name, funs$list_params, funs$calls, funs$roxygen_comment, SIMPLIFY = FALSE)
}, funs$name, funs$list_params, funs$calls, funs$roxygen_comment, SIMPLIFY = TRUE)

out <- as.character(out)
out <- glue::trim(out)
out <- glue::glue_collapse(out, sep = "\n\n")
unclass(out)
Expand Down

0 comments on commit a781c99

Please sign in to comment.