Skip to content

Commit

Permalink
Use tempfile instead of re-creating the same directory in tempdir
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdamoses committed May 16, 2024
1 parent 295a8af commit 94f4741
Show file tree
Hide file tree
Showing 22 changed files with 161 additions and 162 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,19 @@ permissions: read-all

jobs:
R-CMD-check:
runs-on: ubuntu-latest
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
#- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
#- {os: ubuntu-latest, r: 'oldrel-1'}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes
Expand Down
4 changes: 4 additions & 0 deletions R/AllGenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,7 @@ if (!isGeneric("unwrap")) {setGeneric("unwrap", function(x, ...) standardGeneric

#' @export
setGeneric("Img<-", function(x, sample_id = 1L, image_id, scale_fct = 1, value) standardGeneric("Img<-"))

if (!isGeneric("aggregate")) {setGeneric("aggregate", function(x, ...) standardGeneric("aggregate"))}

if (!isGeneric("split")) {setGeneric("split", function(x, f, drop = FALSE, ...) standardGeneric("split"))}
4 changes: 2 additions & 2 deletions R/dimGeometries.R
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,8 @@ nucSeg <- function(x, sample_id = 1L, withDimnames = TRUE) {
#' @examples
#' library(SFEData)
#' library(RBioFormats)
#' fp <- tempdir()
#' dir_use <- XeniumOutput("v2", file_path = file.path(fp, "xenium_test"))
#' fp <- tempfile()
#' dir_use <- XeniumOutput("v2", file_path = fp)
#' # RBioFormats issue
#' try(sfe <- readXenium(dir_use, add_molecules = TRUE))
#' sfe <- readXenium(dir_use, add_molecules = TRUE)
Expand Down
17 changes: 9 additions & 8 deletions R/formatTxSpots.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,14 @@
#' @examples
#' library(SFEData)
#' if (gdalParquetAvailable()) {
#' fp <- tempdir()
#' dir_use <- XeniumOutput("v2", file_path = file.path(fp, "xenium_test"))
#' fp <- tempfile()
#' dir_use <- XeniumOutput("v2", file_path = fp)
#' fn_tx <- formatTxTech(dir_use, tech = "Xenium", flip = TRUE, return = FALSE,
#' file_out = file.path(dir_use, "tx_spots.parquet"))
#' gene_select <- c("ACE2", "BMX")
#' df <- readSelectTx(fn_tx, gene_select)
#'
#' # RBioFormats null pointer error the first time
#' try(sfe <- readXenium(dir_use))
#' sfe <- readXenium(dir_use)
#' sfe <- addSelectTx(sfe, fn_tx, head(rownames(sfe), 5), swap_rownames = "Symbol")
#' unlink(dir_use, recursive = TRUE)
Expand Down Expand Up @@ -292,14 +293,14 @@ addSelectTx <- function(sfe, file, gene_select, sample_id = 1L,
#' @rdname formatTxSpots
#' @examples
#' # Default arguments are for MERFISH
#' fp <- tempdir()
#' dir_use <- SFEData::VizgenOutput(file_path = file.path(fp, "vizgen_test"))
#' fp <- tempfile()
#' dir_use <- SFEData::VizgenOutput(file_path = fp)
#' g <- formatTxSpots(file.path(dir_use, "detected_transcripts.csv"))
#' unlink(dir_use, recursive = TRUE)
#'
#' # For CosMX, note the colnames, also dest = "colGeometry"
#' # Results are written to the tx_spots directory
#' dir_use <- SFEData::CosMXOutput(file_path = file.path(fp, "cosmx_test"))
#' dir_use <- SFEData::CosMXOutput(file_path = fp)
#' cg <- formatTxSpots(file.path(dir_use, "Run5642_S3_Quarter_tx_file.csv"),
#' dest = "colGeometry", z = "all",
#' cell_col = c("cell_ID", "fov"),
Expand Down Expand Up @@ -523,8 +524,8 @@ addTxSpots <- function(sfe, file, sample_id = 1L,
#' @export
#' @examples
#' library(SFEData)
#' fp <- tempdir()
#' dir_use <- XeniumOutput("v2", file_path = file.path(fp, "xenium_test"))
#' fp <- tempfile()
#' dir_use <- XeniumOutput("v2", file_path = fp)
#' fn_tx <- formatTxTech(dir_use, tech = "Xenium", flip = TRUE, return = FALSE,
#' file_out = file.path(dir_use, "tx_spots.parquet"))
#'
Expand Down
4 changes: 4 additions & 0 deletions R/geometry_operation.R
Original file line number Diff line number Diff line change
Expand Up @@ -732,3 +732,7 @@ removeEmptySpace <- function(sfe, sample_id = "all") {
}
sfe
}

#' Aggregate data in SFE using geometry
#'
#' Gene expression and
4 changes: 2 additions & 2 deletions R/image.R
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,8 @@ setMethod("dim", "BioFormatsImage", function(x) {
#' library(EBImage)
#' library(SFEData)
#' library(RBioFormats)
#' fp <- tempdir()
#' fn <- XeniumOutput("v2", file_path = file.path(fp, "xenium_test"))
#' fp <- tempfile()
#' fn <- XeniumOutput("v2", file_path = fp)
#' # Weirdly the first time I get the null pointer error
#' try(sfe <- readXenium(fn))
#' sfe <- readXenium(fn)
Expand Down
12 changes: 6 additions & 6 deletions R/read.R
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ read10xVisiumSFE <- function(samples = "",
#' @importFrom data.table fread merge.data.table rbindlist is.data.table
#' @importFrom stats na.omit
#' @examples
#' fp <- tempdir()
#' dir_use <- SFEData::VizgenOutput(file_path = file.path(fp, "vizgen_test"))
#' fp <- tempfile()
#' dir_use <- SFEData::VizgenOutput(file_path = fp)
#' sfe <- readVizgen(dir_use, z = 3L, image = "PolyT",
#' flip = "geometry")
#'
Expand Down Expand Up @@ -677,8 +677,8 @@ readVizgen <- function(data_dir,
#' @export
#' @concept Read data into SFE
#' @examples
#' fp <- tempdir()
#' dir_use <- SFEData::CosMXOutput(file_path = file.path(fp, "cosmx_test"))
#' fp <- tempfile()
#' dir_use <- SFEData::CosMXOutput(file_path = fp)
#' sfe <- readCosMX(dir_use, z = "all", add_molecules = TRUE)
#' # Clean up
#' unlink(dir_use, recursive = TRUE)
Expand Down Expand Up @@ -835,8 +835,8 @@ readCosMX <- function(data_dir,
#' @examples
#' library(SFEData)
#' library(RBioFormats)
#' fp <- tempdir()
#' dir_use <- XeniumOutput("v2", file_path = file.path(fp, "xenium_test"))
#' fp <- tempfile()
#' dir_use <- XeniumOutput("v2", file_path = fp)
#' # RBioFormats issue
#' try(sfe <- readXenium(dir_use, add_molecules = TRUE))
#' sfe <- readXenium(dir_use, add_molecules = TRUE)
Expand Down
4 changes: 2 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ bbox_center <- function(bbox) {
#' @concept Utilities
#' @examples
#' library(SFEData)
#' fp <- tempdir()
#' dir_use <- XeniumOutput("v1", file_path = file.path(fp, "xenium_test"))
#' fp <- tempfile()
#' dir_use <- XeniumOutput("v1", file_path = fp)
#' # RBioFormats null pointer error
#' try(getPixelSize(file.path(dir_use, "morphology_focus.ome.tif")))
#' getPixelSize(file.path(dir_use, "morphology_focus.ome.tif"))
Expand Down
4 changes: 2 additions & 2 deletions man/Img-set-SpatialExperiment-method.Rd

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

6 changes: 3 additions & 3 deletions man/formatTxSpots.Rd

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

4 changes: 2 additions & 2 deletions man/formatTxTech.Rd

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

4 changes: 2 additions & 2 deletions man/getPixelSize.Rd

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

4 changes: 2 additions & 2 deletions man/readCosMX.Rd

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

7 changes: 4 additions & 3 deletions man/readSelectTx.Rd

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

4 changes: 2 additions & 2 deletions man/readVizgen.Rd

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

4 changes: 2 additions & 2 deletions man/readXenium.Rd

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

4 changes: 2 additions & 2 deletions man/rowGeometries.Rd

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

38 changes: 16 additions & 22 deletions tests/testthat/test-formatTxSpots.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
library(SFEData)
library(sf)
test_that("Read MERFISH transcript spots into rowGeometries", {
fp <- tempdir()
dir_use <- VizgenOutput("hdf5", file_path = file.path(fp, "vizgen_test"))
fp <- tempfile()
dir_use <- VizgenOutput("hdf5", file_path = fp)
sfe <- readVizgen(dir_use, z = 3L, image = "PolyT", add_molecules = TRUE)
expect_equal(rowGeometryNames(sfe), "txSpots")
rg <- txSpots(sfe)
Expand All @@ -15,8 +15,8 @@ test_that("Read MERFISH transcript spots into rowGeometries", {
})

test_that("Format MERFISH transcript spots for colGeometries", {
fp <- tempdir()
dir_use <- VizgenOutput("hdf5", file_path = file.path(fp, "vizgen_test"))
fp <- tempfile()
dir_use <- VizgenOutput("hdf5", file_path = fp)
expect_error(formatTxSpots(file.path(dir_use, "detected_transcripts.csv"),
dest = "colGeometry"),
"file_out must be specified")
Expand Down Expand Up @@ -63,8 +63,8 @@ test_that("Format MERFISH transcript spots for colGeometries", {
})

test_that("Error messages in formatTxSpots", {
fp <- tempdir()
dir_use <- VizgenOutput("hdf5", file_path = file.path(fp, "vizgen_test"))
fp <- tempfile()
dir_use <- VizgenOutput("hdf5", file_path = fp)
file <- file.path(dir_use, "detected_transcripts.csv")
expect_error(formatTxSpots(file, dest = "colGeometry", file_out = NULL),
"file_out must be specified")
Expand All @@ -84,8 +84,8 @@ test_that("Error messages in formatTxSpots", {
})

test_that("Format CosMX spots for colGeometry, multiple z-planes", {
fp <- tempdir()
dir_use <- CosMXOutput(file_path = file.path(fp, "cosmx_test"))
fp <- tempfile()
dir_use <- CosMXOutput(file_path = fp)

cg <- formatTxSpots(file.path(dir_use, "Run5642_S3_Quarter_tx_file.csv"),
dest = "colGeometry", z = "all", z_option = "split",
Expand All @@ -111,8 +111,8 @@ test_that("Format CosMX spots for colGeometry, multiple z-planes", {

test_that("Read transcript spots from a subset of genes", {
skip_if_not(gdalParquetAvailable())
fp <- tempdir()
fn <- XeniumOutput("v2", file_path = file.path(fp, "xenium_test"))
fp <- tempfile()
fn <- XeniumOutput("v2", file_path = fp)
fn_tx <- formatTxTech(fn, tech = "Xenium", flip = TRUE, return = FALSE,
file_out = file.path(fn, "tx_spots.parquet"))
gene_select <- c("ACE2", "BMX")
Expand All @@ -126,8 +126,8 @@ test_that("Read transcript spots from a subset of genes", {

test_that("Error message when Parquet driver is unavailable", {
skip_if(gdalParquetAvailable())
fp <- tempdir()
fn <- XeniumOutput("v2", file_path = file.path(fp, "xenium_test"))
fp <- tempfile()
fn <- XeniumOutput("v2", file_path = fp)
fn_tx <- formatTxTech(fn, tech = "Xenium", flip = TRUE, return = FALSE,
file_out = file.path(fn, "tx_spots.parquet"))
gene_select <- c("ACE2", "BMX")
Expand All @@ -139,8 +139,8 @@ test_that("Error message when Parquet driver is unavailable", {
test_that("Add a subset of spots", {
skip_if_not(gdalParquetAvailable())
library(RBioFormats)
fp <- tempdir()
fn <- XeniumOutput("v2", file_path = file.path(fp, "xenium_test"))
fp <- tempfile()
fn <- XeniumOutput("v2", file_path = fp)
try(sfe <- readXenium(fn))
sfe <- readXenium(fn)
fn_tx <- formatTxTech(fn, tech = "Xenium", flip = TRUE, return = FALSE,
Expand All @@ -155,8 +155,8 @@ test_that("Add a subset of spots", {

test_that("Add subset of spots, multiple files in tx spots output", {
skip_if_not(gdalParquetAvailable())
fp <- tempdir()
dir_use <- CosMXOutput(file_path = file.path(fp, "cosmx_test"))
fp <- tempfile()
dir_use <- CosMXOutput(file_path = fp)

sfe <- readCosMX(dir_use)
fn_tx <- formatTxTech(dir_use, tech = "CosMX", z = "all", z_option = "split",
Expand All @@ -175,9 +175,3 @@ test_that("Add subset of spots, multiple files in tx spots output", {
expect_true(all(is_empty1[-(1:5)]))
unlink(dir_use, recursive = TRUE)
})

# Final cleanup in case failed test messed with cleanup
fp <- tempdir()
unlink(file.path(fp, "cosmx_test"), recursive = TRUE)
unlink(file.path(fp, "vizgen_test"), recursive = TRUE)
unlink(file.path(fp, "xenium_test"), recursive = TRUE)
Loading

0 comments on commit 94f4741

Please sign in to comment.