Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianGoueguel committed Apr 25, 2024
2 parents dddf915 + 846a3d8 commit a9ab0fb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 31 deletions.
3 changes: 0 additions & 3 deletions CRAN-SUBMISSION

This file was deleted.

20 changes: 8 additions & 12 deletions R/ellipseParam.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,22 @@
#'
ellipseParam <- function(data, k = 2, pcx = 1, pcy = 2) {

# check input validity
if (length(data) == 0) {
stop("Seems you forgot to provide data values.")
stop("Data must not be empty.")
}

if (is.data.frame(data) == FALSE & tibble::is_tibble(data) == FALSE) {
stop("Data must be of class data.frame, tbl_df, or tbl")
if (pcx == pcy) {
stop("pcx and pcy must be different.")
}

if (pcx == 0 | pcy == 0) {
stop("No component is provided either in pcx or pcy, or both.")
if (!is.data.frame(data) && !tibble::is_tibble(data)) {
stop("Data must be of class data.frame, tbl_df, or tbl.")
}

if(pcx == pcy) {
stop("Please provide two different components in pcx and pcy.")
if (pcx == 0 || pcy == 0) {
stop("pcx and pcy must be non-zero.")
}

if (k < 2) {
stop("k must be at least equal to 2.")
}

if (k > ncol(data)) {
stop("k exceeds the number of component in the data.")
}
Expand Down
7 changes: 0 additions & 7 deletions cran-comments.md

This file was deleted.

18 changes: 9 additions & 9 deletions tests/testthat/test-test_fun.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ pca_scores <- pca_mod %>%

test_that("ellipseParam: input data", {
pcscores <- tibble::tibble()
expect_error(ellipseParam(data = pcscores), "Seems you forgot to provide data values.")
expect_error(ellipseParam(data = pcscores), "Data must not be empty.")
})


test_that("ellipseCoord: input data", {
pcscores <- tibble::tibble()
expect_error(ellipseParam(data = pcscores), "Seems you forgot to provide data values.")
expect_error(ellipseParam(data = pcscores), "Data must not be empty.")
})


Expand All @@ -31,13 +31,13 @@ test_that("ellipseParam and ellipseCoord functions: k equal to 2", {
res <- ellipseParam(data = pca_scores, k = 2, pcx = 1, pcy = 2)
xy_coord <- ellipseCoord(data = pca_scores, pcx = 1, pcy = 2, conf.limit = 0.95, pts = 200)

expect_error(ellipseParam(data = pca_scores, pcx = 1, pcy = 1), "Please provide two different components in pcx and pcy.")
expect_error(ellipseParam(data = pca_scores, pcx = 0, pcy = 1), "No component is provided either in pcx or pcy, or both.")
expect_error(ellipseCoord(data = pca_scores, pcx = 0, pcy = 1), "No component is provided either in pcx or pcy, or both.")
expect_error(ellipseParam(data = pca_scores, pcx = 1, pcy = 1), "pcx and pcy must be different.")
expect_error(ellipseParam(data = pca_scores, pcx = 0, pcy = 1), "pcx and pcy must be non-zero.")
expect_error(ellipseCoord(data = pca_scores, pcx = 0, pcy = 1), "pcx and pcy must be non-zero.")
expect_error(ellipseParam(data = pca_scores, k = 1), "k must be at least equal to 2.")
expect_error(ellipseParam(data = pca_scores, k = ncol(pca_scores)+1), "k exceeds the number of component in the data.")
expect_error(ellipseCoord(data = pca_scores, pcx = 0, pcy = 1), "No component is provided either in pcx or pcy, or both.")
expect_error(ellipseCoord(data = pca_scores, conf.limit = 2), "Confidence level should be between 0 and 1")
expect_error(ellipseCoord(data = pca_scores, pcx = 0, pcy = 1), "pcx and pcy must be non-zero.")
expect_error(ellipseCoord(data = pca_scores, conf.limit = 2), "Confidence level should be between 0 and 1.")
expect_type(res, "list")
expect_type(xy_coord, "list")
expect_named(res, c("Tsquare", "Ellipse", "cutoff.99pct", "cutoff.95pct"), ignore.order = TRUE, ignore.case = TRUE)
Expand All @@ -54,8 +54,8 @@ test_that("ellipseParam function: k more than 2", {

res1 <- ellipseParam(data = pca_scores, k = 3, pcx = 1, pcy = 2)

expect_error(ellipseParam(data = pca_scores, pcx = 1, pcy = 1), "Please provide two different components in pcx and pcy.")
expect_error(ellipseParam(data = pca_scores, pcx = 0, pcy = 1), "No component is provided either in pcx or pcy, or both.")
expect_error(ellipseParam(data = pca_scores, pcx = 1, pcy = 1), "pcx and pcy must be different.")
expect_error(ellipseParam(data = pca_scores, pcx = 0, pcy = 1), "pcx and pcy must be non-zero.")
expect_error(ellipseParam(data = pca_scores, k = 1), "k must be at least equal to 2.")
expect_error(ellipseParam(data = pca_scores, k = ncol(pca_scores)+1), "k exceeds the number of component in the data.")
expect_type(res1, "list")
Expand Down

0 comments on commit a9ab0fb

Please sign in to comment.