Skip to content

Commit

Permalink
Adding my tests and finshining the lab UofUEpiBio/PHS7045-advanced-pr…
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Nov 14, 2024
1 parent 0425dd0 commit 8980196
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 11 deletions.
10 changes: 7 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Package: egpkg
Package: egpkg2024
Type: Package
Title: What the Package Does in One 'Title Case' Line
Version: 1.0
Expand All @@ -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
4 changes: 3 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 3 additions & 2 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
}

2 changes: 1 addition & 1 deletion R/egpkg-package.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#' @importFrom Rcpp evalCpp
#' @useDynLib egpkg, .registration = TRUE
#' @useDynLib egpkg2024, .registration = TRUE
NULL
29 changes: 29 additions & 0 deletions R/myplot.R
Original file line number Diff line number Diff line change
@@ -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
)
)

}


23 changes: 23 additions & 0 deletions man/myplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Rcpp::Rostream<false>& 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;
Expand All @@ -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);
}
3 changes: 2 additions & 1 deletion src/rcpp_hello_world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -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")
Binary file added tests/testthat/Rplots.pdf
Binary file not shown.
8 changes: 8 additions & 0 deletions tests/testthat/test-myplot.R
Original file line number Diff line number Diff line change
@@ -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))

})

0 comments on commit 8980196

Please sign in to comment.