diff --git a/DESCRIPTION b/DESCRIPTION index f11a912..ec6d785 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,4 +1,4 @@ -Package: egpkg +Package: egpkg2024 Type: Package Title: What the Package Does in One 'Title Case' Line Version: 1.0 @@ -9,8 +9,12 @@ Description: One paragraph description of what the package does as one or more full sentences. License: GPL (>= 2) Imports: - Rcpp + Rcpp, + graphics LinkingTo: Rcpp Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.2 Encoding: UTF-8 +Suggests: + testthat (>= 3.0.0) +Config/testthat/edition: 3 diff --git a/NAMESPACE b/NAMESPACE index 8f279de..8395bc5 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,7 @@ # Generated by roxygen2: do not edit by hand +export(myplot) export(rcpp_hello_world) +import(graphics) importFrom(Rcpp,evalCpp) -useDynLib(egpkg, .registration = TRUE) +useDynLib(egpkg2024, .registration = TRUE) diff --git a/R/RcppExports.R b/R/RcppExports.R index 03501a9..b8f7134 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -2,11 +2,12 @@ # Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 #' Hello world from Rcpp -#' @return A list with two vectors (`x`, `y`). +#' @return +#' A list with two vectors (`x`, `y`). #' @examples #' rcpp_hello_world() #' @export rcpp_hello_world <- function() { - .Call(`_egpkg_rcpp_hello_world`) + .Call(`_egpkg2024_rcpp_hello_world`) } diff --git a/R/egpkg-package.R b/R/egpkg-package.R index d488f21..795bd5b 100644 --- a/R/egpkg-package.R +++ b/R/egpkg-package.R @@ -1,3 +1,3 @@ #' @importFrom Rcpp evalCpp -#' @useDynLib egpkg, .registration = TRUE +#' @useDynLib egpkg2024, .registration = TRUE NULL diff --git a/R/myplot.R b/R/myplot.R new file mode 100644 index 0000000..c3ee0d0 --- /dev/null +++ b/R/myplot.R @@ -0,0 +1,29 @@ +#' Here is the function +#' @param x A numeric vector. +#' @param y A numeric vector. +#' @export +#' @import graphics +#' @examples +#' # Here is an example +#' set.seed(312) +#' x <- rnorm(100) +#' y <- rnorm(100) +#' myplot(x, y) +myplot <- function(x, y) { + + if (!is.numeric(x) | !is.numeric(y)) { + stop("x and y must be numeric") + } + + graphics::plot(x, y, col = "blue", pch = 19, cex = 2) + + invisible( + list( + x = x, + y = y + ) + ) + +} + + diff --git a/man/myplot.Rd b/man/myplot.Rd new file mode 100644 index 0000000..f555ffc --- /dev/null +++ b/man/myplot.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/myplot.R +\name{myplot} +\alias{myplot} +\title{Here is the function} +\usage{ +myplot(x, y) +} +\arguments{ +\item{x}{A numeric vector.} + +\item{y}{A numeric vector.} +} +\description{ +Here is the function +} +\examples{ +# Here is an example +set.seed(312) +x <- rnorm(100) +y <- rnorm(100) +myplot(x, y) +} diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 4433333..f14751b 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -12,7 +12,7 @@ Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); // rcpp_hello_world List rcpp_hello_world(); -RcppExport SEXP _egpkg_rcpp_hello_world() { +RcppExport SEXP _egpkg2024_rcpp_hello_world() { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; @@ -22,11 +22,11 @@ END_RCPP } static const R_CallMethodDef CallEntries[] = { - {"_egpkg_rcpp_hello_world", (DL_FUNC) &_egpkg_rcpp_hello_world, 0}, + {"_egpkg2024_rcpp_hello_world", (DL_FUNC) &_egpkg2024_rcpp_hello_world, 0}, {NULL, NULL, 0} }; -RcppExport void R_init_egpkg(DllInfo *dll) { +RcppExport void R_init_egpkg2024(DllInfo *dll) { R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); R_useDynamicSymbols(dll, FALSE); } diff --git a/src/rcpp_hello_world.cpp b/src/rcpp_hello_world.cpp index fe62d77..a07b972 100644 --- a/src/rcpp_hello_world.cpp +++ b/src/rcpp_hello_world.cpp @@ -3,7 +3,8 @@ using namespace Rcpp; //' Hello world from Rcpp -//' @return A list with two vectors (`x`, `y`). +//' @return +//' A list with two vectors (`x`, `y`). //' @examples //' rcpp_hello_world() //' @export diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000..eba9db0 --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,12 @@ +# This file is part of the standard setup for testthat. +# It is recommended that you do not modify it. +# +# Where should you do additional test configuration? +# Learn more about the roles of various files in: +# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview +# * https://testthat.r-lib.org/articles/special-files.html + +library(testthat) +library(egpkg2024) + +test_check("egpkg2024") diff --git a/tests/testthat/Rplots.pdf b/tests/testthat/Rplots.pdf new file mode 100644 index 0000000..84d2c74 Binary files /dev/null and b/tests/testthat/Rplots.pdf differ diff --git a/tests/testthat/test-myplot.R b/tests/testthat/test-myplot.R new file mode 100644 index 0000000..4c70170 --- /dev/null +++ b/tests/testthat/test-myplot.R @@ -0,0 +1,8 @@ +test_that("multiplication works", { + + expect_error(myplot(1, "o")) + expect_error(myplot("a", 1)) + # expect_s3_class(myplot(1,1), "list") + expect_silent(myplot(1,1)) + +})