Skip to content

Commit

Permalink
Several updates to please R-devel aka R 4.5.0
Browse files Browse the repository at this point in the history
Additional (now mandatory) prefixing of Rf_ before warning and ScalarReal
One switch from class(x) comparison to inherits(x, ...)
  • Loading branch information
eddelbuettel committed Nov 10, 2024
1 parent 75796e9 commit 777d015
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion R/cfunction.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ cfunction <- function(sig=character(), body=character(), includes=character(), o
code <- paste( code, paste(body[[i]], collapse="\n"), sep="")
## CLOSE function, add return and warning in case the user forgot it
code <- paste(code, "\n ",
ifelse(Rcpp, "Rf_warning", "warning"),
ifelse(Rcpp || getRversion() >= "4.5.0", "Rf_warning", "warning"),
"(\"your C program does not return anything!\");\n return R_NilValue;\n}\n", sep="");
}

Expand Down
2 changes: 1 addition & 1 deletion R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ writeCFunc <- function(x, file) {

readCFunc <- function(file) {
x <- readRDS(file)
if (class(x) != "CFunc") stop(file, " does not contain a serialized CFunc object")
if (!inherits(x, "CFunc")) stop(file, " does not contain a serialized CFunc object")

# Get code for restoring after updating the function body
source_code <- x@code
Expand Down
2 changes: 1 addition & 1 deletion inst/tinytest/test_cxxfunction.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ library(inline)

## basic examples from manual page
fx <- cxxfunction(signature(x = "integer", y = "numeric"),
"return ScalarReal(INTEGER(x)[0] * REAL(y)[0]);")
"return Rf_ScalarReal(INTEGER(x)[0] * REAL(y)[0]);")
expect_true(is(fx, "CFunc"))
expect_equal(fx(2L, 5), 10)

Expand Down
2 changes: 1 addition & 1 deletion man/cxxfunction.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ rcpp(..., plugin="Rcpp")
\dontrun{
# default plugin
fx <- cxxfunction(signature(x = "integer", y = "numeric"),
"return ScalarReal(INTEGER(x)[0] * REAL(y)[0]);")
"return Rf_ScalarReal(INTEGER(x)[0] * REAL(y)[0]);")
fx(2L, 5)

# Rcpp plugin
Expand Down
4 changes: 2 additions & 2 deletions man/package.skeleton.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ Generate the skeleton of a package
\dontrun{

fx <- cxxfunction(signature(x = "integer", y = "numeric"),
"return ScalarReal( INTEGER(x)[0] * REAL(y)[0]);")
"return Rf_ScalarReal( INTEGER(x)[0] * REAL(y)[0]);")
package.skeleton("foo", fx)

functions <- cxxfunction(list(ff = signature(),
gg = signature(x = "integer", y = "numeric")),
c("return R_NilValue ;",
"return ScalarReal(INTEGER(x)[0] * REAL(y)[0]);"))
"return Rf_ScalarReal(INTEGER(x)[0] * REAL(y)[0]);"))
package.skeleton("foobar", functions)

}
Expand Down

0 comments on commit 777d015

Please sign in to comment.