diff --git a/.Rbuildignore b/.Rbuildignore index fad0afd4..8ccf1dae 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -11,3 +11,4 @@ ^paper$ ^\.github$ ^man/figures/home +^cran-comments\.md$ diff --git a/DESCRIPTION b/DESCRIPTION index 6fa60432..d4aff74f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,12 +1,12 @@ Package: webmorphR Title: Reproducible Stimuli Date: 2022-05-22 -Version: 0.0.2.9004 +Version: 0.1.0 Authors@R: c(person( given = "Lisa", family = "DeBruine", - role = c("aut", "cre"), + role = c("aut", "cre", "cph"), email = "debruine@gmail.com", comment = c(ORCID = "0000-0002-7523-5539") ), @@ -17,9 +17,9 @@ Authors@R: email = "ekc00004@students.stir.ac.uk" )) Description: Create reproducible image stimuli, - specialised for face images with webmorph.org templates. + specialised for face images with 'psychomorph' or 'webmorph' templates. License: CC BY 4.0 -URL: https://debruine.github.io/webmorphR, https://github.com/debruine/webmorphR +URL: https://debruine.github.io/webmorphR/, https://github.com/debruine/webmorphR BugReports: https://github.com/debruine/webmorphR/issues Depends: R (>= 4.1.0) @@ -45,12 +45,7 @@ Suggests: testthat, usethis, rmarkdown, - covr, - webmorphR.stim, - webmorphR.dlib -Remotes: - debruine/webmorphR.stim, - debruine/webmorphR.dlib + covr Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) diff --git a/NAMESPACE b/NAMESPACE index 3666fc73..bd1dfc95 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -32,7 +32,6 @@ export(delin) export(demo_stim) export(draw_tem) export(features) -export(fpp_auto_delin) export(get_info) export(get_point) export(gglabel) diff --git a/NEWS.md b/NEWS.md index 4a501e18..c194166c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,8 +1,9 @@ -# webmorphR 0.0.2.9004 +# webmorphR 0.1.0.0 * R version requirements decreased from 4.2.0 to 4.1.0 * `quick_delin()` function changed to `delin()` and upgraded to be able to update full templates * `delin()` lets you adjust full templates now, but is still *very* experimental. +* prepared for CRAN # webmorphR 0.0.2.9003 diff --git a/R/align.R b/R/align.R index 6b968e85..02b7edec 100644 --- a/R/align.R +++ b/R/align.R @@ -19,6 +19,7 @@ #' @export #' #' @examples +#' \dontrun{ #' # load stimuli and crop/rotate differently #' stimuli <- demo_stim() |> #' crop(c(0.8, 0.9), c(1.0, 0.9), x_off = c(0, 0.2)) |> @@ -29,9 +30,10 @@ #' #' # align to pupils of second image #' two_pt <- align(stimuli, ref_img = 2) -#' +#' #' # procrustes align to average position #' proc <- align(stimuli, procrustes = TRUE) +#' } align <- function(stimuli, pt1 = 0, pt2 = 1, x1 = NULL, y1 = NULL, x2 = NULL, y2 = NULL, diff --git a/R/auto_delin.R b/R/auto_delin.R index 42d9d731..a0e84584 100644 --- a/R/auto_delin.R +++ b/R/auto_delin.R @@ -1,51 +1,3 @@ -#' Auto-Delineation -#' -#' Automatically delineate faces using dlib in python or Face++ (an external service). Wrapper function for [fpp_auto_delin()] and [webmorphR.dlib::dlib_auto_delin()]. -#' -#' @seealso [fpp_auto_delin], [webmorphR.dlib::dlib_auto_delin()] -#' -#' @param stimuli list of class stimlist -#' @param model Which shape predictor model to use (dlib7, dlib70, fpp106, fpp83) -#' @param replace if FALSE, only gets templates for images with no template -#' @param face which face to delineate in each image if there is more than 1 (only for Face++) -#' @param model_path path to a custom dlib .dat landmark file to use (model is ignored if set) -#' -#' @return stimlist with templates -#' @export -#' -#' @examples -#' \dontrun{ -#' # requires an API key in .Renviron -#' auto_fpp106 <- demo_stim() |> -#' auto_delin(model = "fpp106", replace = TRUE) -#' -#' # requires debruine/webmorphR.dlib -#' auto_dlib7 <- demo_stim() |> -#' auto_delin(replace = TRUE) -#' -#' auto_dlib70 <- demo_stim() |> -#' auto_delin(model = "dlib70", replace = TRUE) -#' } -auto_delin <- function(stimuli, - model = c("dlib7", "dlib70", "fpp106", "fpp83"), - replace = FALSE, - face = 1, - model_path = NULL) { - stimuli <- validate_stimlist(stimuli) - model <- match.arg(model) - - if (model %in% c("fpp106", "fpp83")) { - fpp_auto_delin(stimuli, model, replace, face) - } else if (model %in% c("dlib7", "dlib70") || - !is.null(model_path)) { - if (requireNamespace("webmorphR.dlib", quietly = TRUE)) { - webmorphR.dlib::dlib_auto_delin(stimuli, model, replace, model_path) - } else { - stop("You need to install webmorphR.dlib to use the dlib models\n\nremotes::install_github(\"debruine/webmorphR.dlib\")") - } - } -} - #' Face++ Auto-Delineation #' #' Automatically delineate faces using Face++ (an external service). Since each delineation counts against a daily limit, you need to set up your own Face++ account (see details below). @@ -71,8 +23,8 @@ auto_delin <- function(stimuli, #' auto_fpp106 <- demo_stim() |> #' auto_delin(model = "fpp106", replace = TRUE) #' } -fpp_auto_delin <- function(stimuli, - model = c("dlib7", "dlib70", "fpp106", "fpp83"), +auto_delin <- function(stimuli, + model = c("fpp106", "fpp83"), replace = FALSE, face = 1) { stimuli <- validate_stimlist(stimuli) diff --git a/R/loop.R b/R/loop.R index b8e01b95..77365604 100644 --- a/R/loop.R +++ b/R/loop.R @@ -9,8 +9,10 @@ #' #' @examples #' \dontrun{ -#' stimuli <- webmorphR.stim::load_stim_composite("f_") |> -#' resize(300) +#' stimuli <- demo_stim() |> +#' resize(300) |> +#' rep(4) |> +#' rotate(seq(0, 360-45, 45)) #' loop <- loop(stimuli, 5) #' animate(loop, 10) #' } @@ -23,6 +25,11 @@ loop <- function(stimuli, steps = 10, ...) { stop("You need at least 2 steps") } + n_unique_names <- names(stimuli) |> unique() |> length() + if (n_unique_names < length(stimuli)) { + names(stimuli) <- paste0(seq_along(stimuli), "_", names(stimuli)) + } + from_img <- stimuli to_img <- c(stimuli[2:length(stimuli)], stimuli[1]) p <- seq(0, 1, length.out = steps+1) diff --git a/R/plot.R b/R/plot.R index c2c3d40a..d7fed49e 100644 --- a/R/plot.R +++ b/R/plot.R @@ -142,10 +142,12 @@ plot_stim <- function(stimuli, nrow = NULL, ncol = NULL, byrow = TRUE, #' @export #' #' @examples +#' \dontrun{ #' up <- demo_stim() #' inv <- rotate(up, 180) #' plot_rows(upright = up, inverted = inv) #' plot_rows(upright = up, inverted = inv, color = "dodgerblue", top_label = TRUE) +#' } plot_rows <- function(..., top_label = FALSE) { dots <- list(...) is_stimlist <- sapply(dots, inherits, "stimlist") diff --git a/R/webmorphR-package.R b/R/webmorphR-package.R index f9698430..45b86b4b 100644 --- a/R/webmorphR-package.R +++ b/R/webmorphR-package.R @@ -1,6 +1,6 @@ #' webmorphR: Reproducible Face Stimuli #' -#' Create reproducible image stimuli, specialised for images with webmorph.org templates. See https://debruine.github.io/webmorphR/ for detailed tutorials. +#' Create reproducible image stimuli, specialised for images with webmorph.org templates. #' #' @docType package #' @name webmorphR diff --git a/README.Rmd b/README.Rmd index b190d68e..950fa0d6 100644 --- a/README.Rmd +++ b/README.Rmd @@ -17,7 +17,7 @@ knitr::opts_chunk$set( [![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) -[![Codecov test coverage](https://codecov.io/gh/debruine/webmorphR/branch/master/graph/badge.svg)](https://codecov.io/gh/debruine/webmorphR?branch=master) +[![Codecov test coverage](https://codecov.io/gh/debruine/webmorphR/branch/master/graph/badge.svg)](https://app.codecov.io/gh/debruine/webmorphR?branch=master) [![R-CMD-check](https://github.com/debruine/webmorphR/workflows/R-CMD-check/badge.svg)](https://github.com/debruine/webmorphR/actions) @@ -27,6 +27,12 @@ This development of this package was funded by ERC grant #647910 (KINSHIP). ## Installation +You can (hopefully soon) install webmorphR from CRAN with: + +``` r +install_packages("webmorphR") +``` + You can install the development version from [GitHub](https://github.com/) with: ``` r diff --git a/README.md b/README.md index 2db5a5de..6b1c360c 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ [![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) [![Codecov test -coverage](https://codecov.io/gh/debruine/webmorphR/branch/master/graph/badge.svg)](https://codecov.io/gh/debruine/webmorphR?branch=master) +coverage](https://codecov.io/gh/debruine/webmorphR/branch/master/graph/badge.svg)](https://app.codecov.io/gh/debruine/webmorphR?branch=master) [![R-CMD-check](https://github.com/debruine/webmorphR/workflows/R-CMD-check/badge.svg)](https://github.com/debruine/webmorphR/actions) @@ -23,6 +23,12 @@ This development of this package was funded by ERC grant \#647910 ## Installation +You can (hopefully soon) install webmorphR from CRAN with: + +``` r +install_packages("webmorphR") +``` + You can install the development version from [GitHub](https://github.com/) with: diff --git a/cran-comments.md b/cran-comments.md new file mode 100644 index 00000000..edbfb164 --- /dev/null +++ b/cran-comments.md @@ -0,0 +1,6 @@ +## R CMD check results + +0 errors | 0 warnings | 1 note + +* This is a new release. +* Several examples use dontrun{} because the functions write to disk, create images, or are long processes \ No newline at end of file diff --git a/man/align.Rd b/man/align.Rd index 7f9d7c73..12baf76d 100644 --- a/man/align.Rd +++ b/man/align.Rd @@ -51,6 +51,7 @@ stimlist with aligned tems and/or images Align images so that template points line up. Setting pt1 = pt2 aligns 1 point, but does not resize or rotate images. Setting pt1 and pt2 aligns 2 points, resizing and rotating faces. Setting procrustes = TRUE uses Procrustes analysis to resize and rotate images to be as close as possible to a mean shape. You can specify the x and y coordinates to align, or align to their position in a reference image. The reference image is the average of all images, or the image specified by ref_img. } \examples{ +\dontrun{ # load stimuli and crop/rotate differently stimuli <- demo_stim() |> crop(c(0.8, 0.9), c(1.0, 0.9), x_off = c(0, 0.2)) |> @@ -65,3 +66,4 @@ two_pt <- align(stimuli, ref_img = 2) # procrustes align to average position proc <- align(stimuli, procrustes = TRUE) } +} diff --git a/man/auto_delin.Rd b/man/auto_delin.Rd index 5f0776af..7f00dad7 100644 --- a/man/auto_delin.Rd +++ b/man/auto_delin.Rd @@ -2,47 +2,36 @@ % Please edit documentation in R/auto_delin.R \name{auto_delin} \alias{auto_delin} -\title{Auto-Delineation} +\title{Face++ Auto-Delineation} \usage{ -auto_delin( - stimuli, - model = c("dlib7", "dlib70", "fpp106", "fpp83"), - replace = FALSE, - face = 1, - model_path = NULL -) +auto_delin(stimuli, model = c("fpp106", "fpp83"), replace = FALSE, face = 1) } \arguments{ \item{stimuli}{list of class stimlist} -\item{model}{Which shape predictor model to use (dlib7, dlib70, fpp106, fpp83)} +\item{model}{Which model (fpp106, fpp83)} \item{replace}{if FALSE, only gets templates for images with no template} -\item{face}{which face to delineate in each image if there is more than 1 (only for Face++)} - -\item{model_path}{path to a custom dlib .dat landmark file to use (model is ignored if set)} +\item{face}{which face to delineate in each image if there is more than 1} } \value{ stimlist with templates } \description{ -Automatically delineate faces using dlib in python or Face++ (an external service). Wrapper function for \code{\link[=fpp_auto_delin]{fpp_auto_delin()}} and \code{\link[webmorphR.dlib:dlib_auto_delin]{webmorphR.dlib::dlib_auto_delin()}}. +Automatically delineate faces using Face++ (an external service). Since each delineation counts against a daily limit, you need to set up your own Face++ account (see details below). +} +\details{ +To use Face++ auto-delineation, you need to get your own free API key from https://www.faceplusplus.com. After signing up for an account, go to https://console.faceplusplus.com/app/apikey/list and request a free API key. Add the key and secret to your .Renviron file as follows: + +FACEPLUSPLUS_KEY="1234567890abcdefghijk" + +FACEPLUSPLUS_SECRET="1234567890abcdefghijk" } \examples{ \dontrun{ # requires an API key in .Renviron auto_fpp106 <- demo_stim() |> auto_delin(model = "fpp106", replace = TRUE) - - # requires debruine/webmorphR.dlib - auto_dlib7 <- demo_stim() |> - auto_delin(replace = TRUE) - - auto_dlib70 <- demo_stim() |> - auto_delin(model = "dlib70", replace = TRUE) -} } -\seealso{ -\link{fpp_auto_delin}, \code{\link[webmorphR.dlib:dlib_auto_delin]{webmorphR.dlib::dlib_auto_delin()}} } diff --git a/man/fpp_auto_delin.Rd b/man/fpp_auto_delin.Rd deleted file mode 100644 index e98473da..00000000 --- a/man/fpp_auto_delin.Rd +++ /dev/null @@ -1,42 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/auto_delin.R -\name{fpp_auto_delin} -\alias{fpp_auto_delin} -\title{Face++ Auto-Delineation} -\usage{ -fpp_auto_delin( - stimuli, - model = c("dlib7", "dlib70", "fpp106", "fpp83"), - replace = FALSE, - face = 1 -) -} -\arguments{ -\item{stimuli}{list of class stimlist} - -\item{model}{Which model (fpp106, fpp83)} - -\item{replace}{if FALSE, only gets templates for images with no template} - -\item{face}{which face to delineate in each image if there is more than 1} -} -\value{ -stimlist with templates -} -\description{ -Automatically delineate faces using Face++ (an external service). Since each delineation counts against a daily limit, you need to set up your own Face++ account (see details below). -} -\details{ -To use Face++ auto-delineation, you need to get your own free API key from https://www.faceplusplus.com. After signing up for an account, go to https://console.faceplusplus.com/app/apikey/list and request a free API key. Add the key and secret to your .Renviron file as follows: - -FACEPLUSPLUS_KEY="1234567890abcdefghijk" - -FACEPLUSPLUS_SECRET="1234567890abcdefghijk" -} -\examples{ -\dontrun{ -# requires an API key in .Renviron - auto_fpp106 <- demo_stim() |> - auto_delin(model = "fpp106", replace = TRUE) -} -} diff --git a/man/loop.Rd b/man/loop.Rd index 571e9a74..4798d02c 100644 --- a/man/loop.Rd +++ b/man/loop.Rd @@ -21,8 +21,10 @@ Loop } \examples{ \dontrun{ - stimuli <- webmorphR.stim::load_stim_composite("f_") |> - resize(300) + stimuli <- demo_stim() |> + resize(300) |> + rep(4) |> + rotate(seq(0, 360-45, 45)) loop <- loop(stimuli, 5) animate(loop, 10) } diff --git a/man/plot_rows.Rd b/man/plot_rows.Rd index 4bf1c7b0..7e222845 100644 --- a/man/plot_rows.Rd +++ b/man/plot_rows.Rd @@ -18,8 +18,10 @@ stimlist with plot Plot in rows } \examples{ +\dontrun{ up <- demo_stim() inv <- rotate(up, 180) plot_rows(upright = up, inverted = inv) plot_rows(upright = up, inverted = inv, color = "dodgerblue", top_label = TRUE) } +} diff --git a/man/webmorphR.Rd b/man/webmorphR.Rd index b4eac0bc..206b3a66 100644 --- a/man/webmorphR.Rd +++ b/man/webmorphR.Rd @@ -6,19 +6,19 @@ \alias{webmorphR-package} \title{webmorphR: Reproducible Face Stimuli} \description{ -Create reproducible image stimuli, specialised for images with webmorph.org templates. See https://debruine.github.io/webmorphR/ for detailed tutorials. +Create reproducible image stimuli, specialised for images with webmorph.org templates. } \seealso{ Useful links: \itemize{ - \item \url{https://debruine.github.io/webmorphR} + \item \url{https://debruine.github.io/webmorphR/} \item \url{https://github.com/debruine/webmorphR} \item Report bugs at \url{https://github.com/debruine/webmorphR/issues} } } \author{ -\strong{Maintainer}: Lisa DeBruine \email{debruine@gmail.com} (\href{https://orcid.org/0000-0002-7523-5539}{ORCID}) +\strong{Maintainer}: Lisa DeBruine \email{debruine@gmail.com} (\href{https://orcid.org/0000-0002-7523-5539}{ORCID}) [copyright holder] Other contributors: \itemize{ diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index 384cfcbe..29a7f055 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -7,6 +7,10 @@ home: title: Reproducible Stimuli description: Create reproducible image stimuli, specialised for images with webmorph.org templates. +authors: + Lisa DeBruine: + href: https://debruine.github.io/ + template: bootstrap: 5 bootswatch: yeti @@ -71,7 +75,6 @@ reference: - '`change_lines`' - '`delin`' - '`draw_tem`' - - '`fpp_auto_delin`' - '`squash_tem`' - '`subset_tem`' - '`remove_tem`' diff --git a/tests/testthat/test-animate.R b/tests/testthat/test-animate.R index cf8a79a3..81227717 100644 --- a/tests/testthat/test-animate.R +++ b/tests/testthat/test-animate.R @@ -10,7 +10,8 @@ test_that("animate", { expect_equal(info$format, rep("gif", 2)) ## args - x <- webmorphR.stim::load_stim_zoom() |> + x <- demo_stim()[1] |> rep(4) |> + rotate(c(0, 90, 180, 270)) |> animate(fps = 4, loop = 2, rev = TRUE) # rev = TRUE doubles the frames diff --git a/tests/testthat/test-auto_delin.R b/tests/testthat/test-auto_delin.R index df5bc5fc..d4e8239a 100644 --- a/tests/testthat/test-auto_delin.R +++ b/tests/testthat/test-auto_delin.R @@ -2,16 +2,7 @@ test_that("auto_delin", { stimuli <- demo_stim("test", "f") expect_error(auto_delin()) expect_error( auto_delin(stimuli, "dd") ) - - expect_warning( x <- auto_delin(stimuli, "fpp106", - face = 3, replace = TRUE), - "f_multi did not have 3 faces") - - # all images have templates - expect_warning(x <- auto_delin(stimuli, "dlib7")) - expect_equal(x, stimuli) - expect_warning(x <- auto_delin(stimuli, "fpp106")) - expect_equal(x, stimuli) + expect_error(x <- auto_delin(stimuli, "dlib7")) # remove key and secret to test error message key <- Sys.getenv("FACEPLUSPLUS_KEY") @@ -21,9 +12,9 @@ test_that("auto_delin", { Sys.setenv(FACEPLUSPLUS_KEY = "") Sys.setenv(FACEPLUSPLUS_SECRET = "") fpp_error <- "You need to set FACEPLUSPLUS_KEY and FACEPLUSPLUS_SECRET in your .Renviron (see ?auto_delin)" - expect_error( auto_delin(x, "fpp106", replace = TRUE), + expect_error( auto_delin(stimuli, "fpp106", replace = TRUE), fpp_error, fixed = TRUE) - expect_error( auto_delin(x, "fpp83", replace = TRUE), + expect_error( auto_delin(stimuli, "fpp83", replace = TRUE), fpp_error, fixed = TRUE) Sys.setenv(FACEPLUSPLUS_KEY = key) Sys.setenv(FACEPLUSPLUS_SECRET = secret) @@ -34,54 +25,32 @@ test_that("auto_delin", { skip_on_cran() skip_if_offline() + # all images have templates + stimuli <- demo_stim("test", "f") + expect_warning(x <- auto_delin(stimuli, "fpp106")) + expect_equal(x, stimuli) + + expect_warning( x <- auto_delin(stimuli, "fpp106", + face = 3, replace = TRUE), + "f_multi did not have 3 faces") + stimuli <- demo_stim("test", "m") ad <- auto_delin(stimuli, "fpp106", replace = TRUE) - fpp <- fpp_auto_delin(stimuli, "fpp106", replace = TRUE) + fpp <- auto_delin(stimuli, "fpp106", replace = TRUE) expect_equal(fpp[[1]]$points, ad[[1]]$points) expect_equal(fpp[[1]]$lines, ad[[1]]$lines) }) -test_that("fpp_auto_delin", { - # Requires FACEPLUSPLUS_KEY and FACEPLUSPLUS_SECRET - skip_on_cran() - skip_if_offline() - - stimuli <- demo_stim("test", "f") - fpp106 <- tem_def("fpp106") - x106 <- fpp_auto_delin(stimuli, "fpp106", replace = TRUE) - pnames <- (x106$f_multi$points |> dimnames())[[2]] - expect_equal(pnames, fpp106$points$name) - expect_equal(x106$f_multi$lines, fpp106$lines) - - fpp83 <- tem_def("fpp83") - x83 <- fpp_auto_delin(stimuli, "fpp83", replace = TRUE) - pnames <- (x83$f_multi$points |> dimnames())[[2]] - expect_equal(pnames, fpp83$points$name) - expect_equal(x83$f_multi$lines, fpp83$lines) -}) - - test_that("paste 2 together", { skip_on_cran() skip_if_offline() s <- demo_stim() |> plot() - f <- fpp_auto_delin(s, "fpp106", TRUE, 1) - m <- fpp_auto_delin(s, "fpp106", TRUE, 2) + f <- auto_delin(s, "fpp106", TRUE, 1) + m <- auto_delin(s, "fpp106", TRUE, 2) expect_true(all((f[[1]]$points == m[[1]]$points) == FALSE)) # draw_tem(c(f, m)) |> plot(nrow = 2) }) -test_that("dlib_auto_delin", { - skip_on_cran() - skip_if_offline() - skip_on_ci() - - stimuli <- demo_stim()[1] - s_dlib <- webmorphR.dlib::dlib_auto_delin(stimuli, "dlib7", TRUE) - s_ad <- auto_delin(stimuli, "dlib7", TRUE) - expect_equal(s_dlib[[1]]$points, s_ad[[1]]$points) - expect_equal(s_dlib[[1]]$lines, s_ad[[1]]$lines) -}) diff --git a/tests/testthat/test-avg.R b/tests/testthat/test-avg.R index 14cc13d2..d5b8aad5 100644 --- a/tests/testthat/test-avg.R +++ b/tests/testthat/test-avg.R @@ -3,20 +3,23 @@ # avg ---- test_that("avg", { skip_on_cran() + skip_if_offline() # can't average more than 100 images - stim120 <- rep(demo_stim(), 60) + stim120 <- demo_stim() |> rep(60) expect_error(avg(stim120)) # normalisation - stimuli <- webmorphR.stim::load_stim_lisa(1:2) + stimuli <- demo_stim() avg <- avg(stimuli) twopoint <- avg(stimuli, norm = "twopoint") rigid <- avg(stimuli, norm = "rigid") notex <- avg(stimuli, texture = FALSE) tem <- average_tem(stimuli) - expect_equal(tem[[1]]$points, avg[[1]]$points) + dif <- tem[[1]]$points - avg[[1]]$points + expect_lt(max(dif), 1) + expect_gt(min(dif), -1) expect_true(compare(avg, twopoint) > 0) expect_true(compare(avg, rigid) > 0) expect_true(compare(avg, notex) > 0) diff --git a/tests/testthat/test-continuum.R b/tests/testthat/test-continuum.R index 1f95fdf3..6441cc93 100644 --- a/tests/testthat/test-continuum.R +++ b/tests/testthat/test-continuum.R @@ -2,6 +2,7 @@ test_that("continuum", { skip_on_cran() + skip_if_offline() stimuli <- demo_stim() diff --git a/tests/testthat/test-loop.R b/tests/testthat/test-loop.R index 4946d655..e42cdcd1 100644 --- a/tests/testthat/test-loop.R +++ b/tests/testthat/test-loop.R @@ -1,9 +1,12 @@ #wm_opts(server = "https://webmorph.test") test_that("loop", { + skip_on_cran() + skip_if_offline() + stimuli <- demo_stim() expect_error(loop(stimuli[1])) - expect_error(lopp(stimuli, 1)) + expect_error(loop(stimuli, 1)) loop <- loop(stimuli, 2) @@ -16,6 +19,17 @@ test_that("loop", { "f_multi_m_multi_1", "f_multi_m_multi_2") expect_equal(names(revloop), nm) + # stim with same names + reploop <- demo_stim() |> + rep(2) |> + rotate(c(0, 30, 60, 90)) |> + loop(2) + + nm <- c("1_f_multi_2_m_multi_1", "1_f_multi_2_m_multi_2", "2_m_multi_3_f_multi_1", + "2_m_multi_3_f_multi_2", "3_f_multi_4_m_multi_1", "3_f_multi_4_m_multi_2", + "4_m_multi_1_f_multi_1", "4_m_multi_1_f_multi_2") + expect_equal(names(reploop), nm) + ## visual checks ---- # stimuli <- webmorphR.stim::load_stim_composite(c(1,6,7,2,4,9,10,5)) |> # resize(300) diff --git a/tests/testthat/test-mask_oval.R b/tests/testthat/test-mask_oval.R index d9f62218..0c5be416 100644 --- a/tests/testthat/test-mask_oval.R +++ b/tests/testthat/test-mask_oval.R @@ -1,5 +1,5 @@ test_that("mask_oval", { - stimuli <- webmorphR.stim::load_stim_lisa(1:2) + stimuli <- demo_stim() expect_silent(x <- mask_oval(stimuli, each = TRUE)) expect_silent(y <- mask_oval(stimuli, each = FALSE)) diff --git a/tests/testthat/test-symmetrise.R b/tests/testthat/test-symmetrise.R index 4aa5ee0c..f4aa45dc 100644 --- a/tests/testthat/test-symmetrise.R +++ b/tests/testthat/test-symmetrise.R @@ -2,6 +2,8 @@ # frl ---- test_that("frl", { + skip_on_cran() + stimuli <- demo_stim("tem_examples", "frl") sym_both <- symmetrize(stimuli) sym_shape <- symmetrize(stimuli, color = 0) @@ -30,6 +32,8 @@ test_that("frl", { # fpp106 ---- test_that("fpp106", { + skip_on_cran() + tem_id <- "fpp106" stimuli <- demo_stim("tem_examples", tem_id) @@ -56,6 +60,8 @@ test_that("fpp106", { # fpp83 ---- test_that("fpp83", { + skip_on_cran() + tem_id <- "fpp83" stimuli <- demo_stim("tem_examples", tem_id) @@ -83,6 +89,9 @@ test_that("fpp83", { # dlib70 ---- test_that("dlib70", { + skip_on_cran() + skip_if_offline() + tem_id <- "dlib70" stimuli <- demo_stim("tem_examples", tem_id) @@ -109,6 +118,8 @@ test_that("dlib70", { # dlib7 ---- test_that("dlib7", { + skip_on_cran() + tem_id <- "dlib7" stimuli <- demo_stim("tem_examples", tem_id)[1] diff --git a/tests/testthat/test-trans.R b/tests/testthat/test-trans.R index 8c850f02..0216c8ab 100644 --- a/tests/testthat/test-trans.R +++ b/tests/testthat/test-trans.R @@ -2,6 +2,7 @@ test_that("trans", { skip_on_cran() + skip_if_offline() s <- demo_stim() diff --git a/vignettes/masking.Rmd b/vignettes/masking.Rmd index 6835976e..831c74a1 100644 --- a/vignettes/masking.Rmd +++ b/vignettes/masking.Rmd @@ -30,6 +30,7 @@ This vignette explains templates and shows you how to mask images relative to th # load packages and set maximum plot width library(webmorphR) library(webmorphR.stim) # for extra stimulus sets +library(webmorphR.dlib) # for dlib auto-delineation wm_opts(plot.maxwidth = 850) # load the demo stimuli @@ -122,7 +123,7 @@ c(dlib7s, dlib70s, fpp106s, fpp83s) |> If your images aren't delineated, you can use the `auto_delin()` function or upload them to [webmorph](webmorph.org) to use the extensive manual delineation functions there and the 189-point FRL template. -The auto-delineation has three options. +The auto-delineation has two options. #### dlib @@ -238,8 +239,8 @@ s <- demo_stim() |> pad(20, fill = "dodgerblue") # get delineations for the first and second face -face1 <- fpp_auto_delin(s, "fpp106", TRUE, 1) -face2 <- fpp_auto_delin(s, "fpp106", TRUE, 2) +face1 <- auto_delin(s, "fpp106", TRUE, 1) +face2 <- auto_delin(s, "fpp106", TRUE, 2) # add template viz and plot c(face1, face2) |> draw_tem() |> plot(nrow = 2) diff --git a/vignettes/webmorphR.Rmd b/vignettes/webmorphR.Rmd index e4c39757..9434c30f 100644 --- a/vignettes/webmorphR.Rmd +++ b/vignettes/webmorphR.Rmd @@ -25,6 +25,7 @@ You can install the development version from [GitHub](https://github.com/), as w # install.packages("remotes") remotes::install_github("debruine/webmorphR") remotes::install_github("debruine/webmorphR.stim") +remotes::install_github("debruine/webmorphR.dlib") ``` Installation can take a few minutes, depending on how many dependency packages you need to install. @@ -32,6 +33,7 @@ Installation can take a few minutes, depending on how many dependency packages y ```{r} library(webmorphR) library(webmorphR.stim) # for extra stimulus sets +library(webmorphR.dlib) # for dlib auto-delineation wm_opts(plot.maxwidth = 850) # set maximum width for plot output ```