test and everything

This commit is contained in:
AG Damsbo 2022-09-22 11:17:09 +02:00
parent c45fd3370c
commit f2417bd16b
10 changed files with 67 additions and 1 deletions

View File

@ -9,3 +9,6 @@ License: GPL-3
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.1
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3

View File

@ -1,3 +1,4 @@
# Generated by roxygen2: do not edit by hand
export(filter2)
export(select2)

18
R/filter2.R Normal file
View File

@ -0,0 +1,18 @@
#' Filter function
#'
#' Alternative filtering function
#'
#' @param ds data frame
#' @param test logical vector , indices or row names
#'
#' @return Data frame filtered by test
#' @export
#'
#' @examples
#' filter2(iris,iris$Species=="virginica")
#' filter2(iris,2:10)
filter2 <- function(ds,test) {
ds[test,]
}

23
man/filter2.Rd Normal file
View File

@ -0,0 +1,23 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/filter2.R
\name{filter2}
\alias{filter2}
\title{Filter function}
\usage{
filter2(ds, test)
}
\arguments{
\item{ds}{data frame}
\item{test}{logical vector , indices or row names}
}
\value{
Data frame filtered by test
}
\description{
Alternative filtering function
}
\examples{
filter2(iris,iris$Species=="virginica")
filter2(iris,2:10)
}

View File

@ -1,5 +1,5 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/slctr.R
% Please edit documentation in R/select2.R
\name{select2}
\alias{select2}
\title{Simple select function using subset()}

View File

@ -4,3 +4,4 @@ dir.create("R")
usethis::use_package_doc()
usethis::use_roxygen_md()
usethis::use_package()

12
tests/testthat.R Normal file
View File

@ -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/tests.html
# * https://testthat.r-lib.org/reference/test_package.html#special-files
library(testthat)
library(minidplyr)
test_check("minidplyr")

View File

@ -0,0 +1,5 @@
test_that("filter2() works with logicla vectors", {
df <- filter2(iris,c(T,F))
expect_s3_class(df, "data.frame")
expect_equal(dim(df), dim(iris)/2:1)
})

View File

@ -0,0 +1,3 @@
test_that("multiplication works", {
expect_equal(2 * 2, 4)
})