Skip to content

Commit

Permalink
fixes for finding readers with format
Browse files Browse the repository at this point in the history
* sometimes we were relying on the format being ignored ...
  • Loading branch information
jefferis committed Aug 7, 2024
1 parent 35d75e8 commit 27040ea
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions R/neuron-io.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ read.neuron<-function(f, format=NULL, class=c("neuron", "ngraph"), ...){
# use ext as backup if format is missing
ext=if(is.null(format))
tolower(sub(".*\\.([^.]+$)","\\1",basename(f))) else ""
if(format=="rds" || ext=='rds')
if(!is.null(format) && format %in% c("ply", "obj", "ngmesh"))
format=paste0("neuron.", format)
if(isTRUE(format=="rds") || ext=='rds')
n=readRDS(f)
else if(format=="rda" || ext=='rda'){
else if(isTRUE(format=="rda") || ext=='rda'){
objname=load(f, envir=environment())
if(length(objname)>1) stop("More than 1 object in file:",f)
n=get(objname,envir=environment())
Expand Down Expand Up @@ -185,6 +185,8 @@ read.neurons<-function(paths, pattern=NULL, neuronnames=NULL, format=NULL,
on.exit(unlink(paths))
download.file(url, destfile = paths)
}
# the neurons inside the zip file will not have format zip
if(isTRUE(format=='zip')) format=NULL
neurons_dir <- file.path(tempfile(pattern = "user_neurons"))
on.exit(unlink(neurons_dir, recursive=TRUE), add = TRUE)
unzip(paths, exdir=neurons_dir)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-neuron-io.R
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,14 @@ test_that("we can read hxskel format neurons",{
})

test_that("we can read multiple neurons from a zip archive", {
files_to_zip <- c("testdata/neuron/testneuron_am3d.am", "testdata/neuron/testneuron_lineset.am")
files_to_zip <- test_path(c("testdata/neuron/testneuron_am3d.am", "testdata/neuron/testneuron_lineset.am"))
# swallow extraneous warning
expect_warning(neurons <- read.neurons(files_to_zip,
neuronnames = function(f) tools::file_path_sans_ext(basename(f))),
regexp = "specifies radius")
zip_file <- paste0(tempfile(), ".zip")
on.exit(unlink(zip_file, recursive=TRUE))
zip(zip_file, files_to_zip)
zip(zip_file, files_to_zip, flags = "-r9Xq")
expect_warning(zip_neurons <- read.neurons(zip_file, format="zip",
neuronnames = function(f) tools::file_path_sans_ext(basename(f))),
regexp = "specifies radius")
Expand Down

0 comments on commit 27040ea

Please sign in to comment.