Skip to content

Commit

Permalink
Merge branch 'main' into fix/x3p_rotate
Browse files Browse the repository at this point in the history
  • Loading branch information
heike committed Mar 5, 2024
2 parents 0b49857 + 33d1952 commit ce9f822
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: x3ptools
Type: Package
Title: Tools for Working with 3D Surface Measurements
Version: 0.0.4
Version: 0.0.4.9000
Date: 2024-01-21
Authors@R: c(
person("Heike", "Hofmann", role = c("aut", "cre", "cph"),
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export(x3p_mask_quantile)
export(x3p_modify_xml)
export(x3p_read)
export(x3p_read_dat)
export(x3p_read_folder)
export(x3p_read_plux)
export(x3p_rotate)
export(x3p_sample)
Expand All @@ -67,6 +68,7 @@ importFrom(assertthat,assert_that)
importFrom(digest,digest)
importFrom(dplyr,add_tally)
importFrom(dplyr,arrange)
importFrom(dplyr,as_tibble)
importFrom(dplyr,between)
importFrom(dplyr,desc)
importFrom(dplyr,filter)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

# x3ptools 0.0.4.9000

## minor functionality

* `x3p_read_folder` allows an import of multiple x3p files (recursively) into a single data frame (in tibble format) with a list variable of x3p objects.


# x3ptools 0.0.4

Expand Down
22 changes: 22 additions & 0 deletions R/x3p_read_folder.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#' Read all x3p files in a folder
#'
#' This function is provided with a path to a folder, it will search recursively for all x3p files within the folder, read the x3p files, and return the results as part of a tibble dataset.
#' @param path character string to a folder
#' @return tibble with two variables: source contains the file path to the x3p file, and x3p is a list variable of x3p objects.
#' @export
#' @importFrom dplyr as_tibble
#' @examples
#' # example code
#' path <- dirname(system.file("csafe-logo.x3p", package="x3ptools"))
#' x3p_read_folder(path) # show all x3p files installed with x3ptools
x3p_read_folder <- function(path) {
files <- dir(path, pattern = ".x3p$", ignore.case = TRUE, recursive = TRUE, full.names = TRUE, include.dirs = TRUE)
if (length(files) == 0) {
warning(sprintf("No x3p files found at '%s'", path))
return(dplyr::as_tibble(data.frame("source" = NULL, "x3p" = NULL)))
}
read_x3p_try <- function(...) try(x3ptools::x3p_read(...))
scans <- lapply(files, FUN = read_x3p_try)

dplyr::as_tibble(data.frame(source = files, x3p = I(scans), stringsAsFactors = F))
}
4 changes: 4 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,7 @@ x3p_image(logoplus, size=c(741, 419)/2, zoom=0.5, multiply = 30, file="man/figur
```{r, echo=FALSE}
knitr::include_graphics("man/figures/logo-lines.png")
```

### Acknowledgement

This work was partially funded by the Center for Statistics and Applications in Forensic Evidence (CSAFE) through Cooperative Agreements 70NANB15H176 and 70NANB20H019 between NIST and Iowa State University, which includes activities carried out at Carnegie Mellon University, Duke University, University of California Irvine, University of Virginia, West Virginia University, University of Pennsylvania, Swarthmore College and University of Nebraska, Lincoln.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ status](https://www.r-pkg.org/badges/version/x3ptools)](https://CRAN.R-project.o
downloads](https://cranlogs.r-pkg.org/badges/last-month/x3ptools?color=blue)](https://r-pkg.org/pkg/x3ptools)
[![Lifecycle:
stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![Last-changedate](https://img.shields.io/badge/last%20change-2024--03--02-yellowgreen.svg)](https://github.com/heike/x3ptools/commits/main)
[![Last-changedate](https://img.shields.io/badge/last%20change-2024--03--04-yellowgreen.svg)](https://github.com/heike/x3ptools/commits/main)
[![Codecov test
coverage](https://codecov.io/gh/heike/x3ptools/graph/badge.svg?token=80NyJNOg5b)](https://app.codecov.io/gh/heike/x3ptools)
[![R-CMD-check](https://github.com/heike/x3ptools/workflows/R-CMD-check/badge.svg)](https://github.com/heike/x3ptools/actions)
Expand Down Expand Up @@ -178,6 +178,11 @@ visualize these raster images, e.g. using `ggplot2`:

``` r
library(ggplot2)
```

## Warning: package 'ggplot2' was built under R version 4.3.2

``` r
library(magrittr)

logo_df %>% ggplot(aes( x= x, y=y, fill= value)) +
Expand Down Expand Up @@ -332,3 +337,13 @@ x3p_image(logoplus, size=c(741, 419)/2, zoom=0.5, multiply = 30, file="man/figur
```

<img src="man/figures/logo-lines.png" width="370" />

### Acknowledgement

This work was partially funded by the Center for Statistics and
Applications in Forensic Evidence (CSAFE) through Cooperative Agreements
70NANB15H176 and 70NANB20H019 between NIST and Iowa State University,
which includes activities carried out at Carnegie Mellon University,
Duke University, University of California Irvine, University of
Virginia, West Virginia University, University of Pennsylvania,
Swarthmore College and University of Nebraska, Lincoln.
22 changes: 22 additions & 0 deletions man/x3p_read_folder.Rd

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

14 changes: 14 additions & 0 deletions tests/testthat/test_read_x3p_folder.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
context("x3p_read_folder")


test_that("x3p_read_folder works as expected", {

# Test nonexistent file path
expect_warning(x3p_read_folder(file.path("does", "not", "exist")))

# Test files installed with x3ptools
path <- dirname(system.file("csafe-logo.x3p", package="x3ptools"))
res <- x3p_read_folder(path) # show all x3p files installed with x3ptools
expect_equal(names(res), c("source", "x3p"))
expect_equal(class(res$x3p[[1]]), "x3p")
})

0 comments on commit ce9f822

Please sign in to comment.