Skip to content

Commit

Permalink
Style/comments
Browse files Browse the repository at this point in the history
  • Loading branch information
keller-mark committed Oct 18, 2023
1 parent 7074da3 commit 937bbc5
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 42 deletions.
8 changes: 4 additions & 4 deletions R/array-nested.R
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,11 @@ NestedArray <- R6::R6Class("NestedArray",
}
return(buf)
},
#' Convert NestArray object to R array
#' Convert NestArray object to R array (for S3 method)
#'
#' @return array
as.array = function(){
#Consider using drop() to simplify dimensions of 1
as.array = function() {
# Consider using drop() to simplify dimensions of 1
return(self$data)
}
)
Expand All @@ -315,6 +315,6 @@ NestedArray <- R6::R6Class("NestedArray",
#' @param obj
#' @keywords internal
#' @export
as.array.NestedArray = function(obj){
as.array.NestedArray = function(obj) {
obj$as.array()
}
71 changes: 36 additions & 35 deletions R/zarr-array.R
Original file line number Diff line number Diff line change
Expand Up @@ -889,68 +889,69 @@ ZarrArray <- R6::R6Class("ZarrArray",
get_dimension_separator = function() {
return(private$dimension_separator)
},
#' Subset / slice Zarr object using bracket notation
#' Set values for a selection using bracket notation (for S3 method).
#'
#' @param ... Contains the slicing parameters, one for each dimension.
#' Use empty space to get whole dimension e.g. [1:5,,]
#'
#' @return Sliced Zarr object
#' @keywords internal
`[` = function(...) {
filters = substitute(...())
if(length(filters) != length(private$shape)){
stop("This Zarr object has ",length(private$shape)," dimensions, ",
length(filters)," were supplied")
}
filters = lapply(filters, function(x){
#Proceed based on type of filter
if(typeof(x) == "symbol"){
#When empty dimension, return everything
if(x == ""){
filters <- substitute(...())
if(length(filters) != length(private$shape)) {
stop("This Zarr object has ", length(private$shape), " dimensions, ", length(filters), " were supplied")
}
filters <- lapply(filters, function(x) {
# Proceed based on type of filter
if(typeof(x) == "symbol") {
# When empty dimension, return everything
if(x == "") {
return(NULL)
} else {
stop("Unsupported filter '", as.character(x), "' supplied")
}

} else if(typeof(x) == "double"){
#Return single value for dimension
} else if(typeof(x) == "double") {
# Return single value for dimension
return(slice(x, x))
} else if(typeof(x) == "language"){
x = as.list(x)
#Return a range (supplied via : or seq())
if(x[[1]] == ":"){
} else if(typeof(x) == "language") {
x <- as.list(x)
# Return a range (supplied via : or seq())
if(x[[1]] == ":") {
return(slice(x[[2]], x[[3]]))
} else if(x[[1]] == "seq"){
argNames <- names(x)
from <- ifelse("from" %in% argNames, x[[which("from" == argNames)]], x[[2]])
to <- ifelse("to" %in% argNames, x[[which("to" == argNames)]], x[[3]])
if(length(x) > 3){
} else if(x[[1]] == "seq") {
arg_names <- names(x)
from <- ifelse("from" %in% arg_names, x[[which("from" == arg_names)]], x[[2]])
to <- ifelse("to" %in% arg_names, x[[which("to" == arg_names)]], x[[3]])
if(length(x) > 3) {
stop("Slicing with step size is not supported yet")
by <- ifelse("by" %in% argNames, x[[which("by" == argNames)]], x[[4]])
by <- ifelse("by" %in% arg_names, x[[which("by" == arg_names)]], x[[4]])
} else {
by <- NA
}
return(slice(from, to, by))
} else if(x[[1]] == "c"){
stop("Custom vector slicing is not supported yet")
} else if(x[[1]] == "c") {
stop("Custom vector slicing is not yet supported")
# return(eval(y))
} else{
} else {
stop("Unsupported filter '", as.character(x), "' supplied")
}

} else {
stop("Unsupported filter '", as.character(x), "' supplied")
}
})
return(self$get_basic_selection(filters))
return(self$get_item(filters))
},
#' Assign values for a selection using bracket notation (for S3 method).
#' @keywords internal
`[<-` = function(...) {
stop("Updating values using bracket subsetting is currently not possible")
stop("Assignment using bracket notation is not yet supported - use set_item() directly")
},
#' Convert Zarr object to R array
#' Convert Zarr object to R array (for S3 method). Note that this loads all data into memory.
#'
#' @return array
as.array = function(){
return(self$get_basic_selection("...")$data)
as.array = function() {
return(self$get_item("...")$data)
}
)
)
Expand All @@ -962,7 +963,7 @@ ZarrArray <- R6::R6Class("ZarrArray",
#' @param ...
#' @keywords internal
#' @export
`[.ZarrArray` <- function(obj, ...){
`[.ZarrArray` <- function(obj, ...) {
obj$`[`(...)
}

Expand All @@ -972,7 +973,7 @@ ZarrArray <- R6::R6Class("ZarrArray",
#' @param ...
#' @keywords internal
#' @export
`[<-.ZarrArray` <- function(obj, ...){
`[<-.ZarrArray` <- function(obj, ...) {
obj$`[<-`(...)
}

Expand All @@ -981,6 +982,6 @@ ZarrArray <- R6::R6Class("ZarrArray",
#' @param obj
#' @keywords internal
#' @export
as.array.ZarrArray = function(obj){
as.array.ZarrArray = function(obj) {
obj$as.array()
}
2 changes: 1 addition & 1 deletion man/NestedArray.Rd

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

28 changes: 26 additions & 2 deletions man/ZarrArray.Rd

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

0 comments on commit 937bbc5

Please sign in to comment.