Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ exportClasses(H5Group)
exportClasses(H5Location)
exportMethods("[")
exportMethods("[<-")
exportMethods("[[")
exportMethods("[[<-")
exportMethods("h5attr<-")
exportMethods(c)
exportMethods(createAttribute)
Expand Down
47 changes: 38 additions & 9 deletions R/CommonFG.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
#' specifies the group to be created/accesses and the second the dataset name.
#'
#' Groups can be created/accessed by simply using one character parameter, e.g.
#' \code{group <- obj["groupname"]}.
#' \code{group <- obj[["groupname"]]}.
#'
#' DataSets can be either accessed by using
#' \code{dset <- obj["groupname", "datasetname"]} if existing or initialized by
#' using \code{obj["groupname", "datasetname"] <- value}.
#' \code{dset <- obj[["groupname", "datasetname"]]} if existing or initialized by
#' using \code{obj[["groupname", "datasetname"]] <- value}.
#'
#' All created objects e.g. \code{group} or \code{dset} should be closed in the
#' end using \code{h5close}.
Expand All @@ -36,13 +36,13 @@
#' @examples
#' file <- h5file("test.h5")
#' # Create new DataSet 'testset' in H5Group 'testgroup'
#' file["testgroup/testset"] <- matrix(1:9, nrow = 3)
#' file[["testgroup/testset"]] <- matrix(1:9, nrow = 3)
#' # Create new DataSet 'testset2' in file root
#' file["testset2"] <- 1:10
#' file[["testset2"]] <- 1:10
#' # Retrieve H5Group 'testgroup'
#' group <- file["testgroup"]
#' group <- file[["testgroup"]]
#' # Retrieve DataSet 'testset'
#' dset <- group["testset"]
#' dset <- group[["testset"]]
#' h5close(dset)
#' h5close(group)
#' h5close(file)
Expand All @@ -59,7 +59,7 @@ setGeneric("h5close", function(.Object)

#' @rdname CommonFG
#' @export
setMethod("[", c("CommonFG", "character", "ANY"),
setMethod("[[", c("CommonFG", "character", "ANY"),
function(x, i, ..., drop=TRUE) {
if(length(i) > 1) {
stop("Only one path can be specified.")
Expand All @@ -84,7 +84,7 @@ setMethod("[", c("CommonFG", "character", "ANY"),
#' @param value vector/matrix/array; Value to be assigend to dataset
#' @rdname CommonFG
#' @export
setMethod("[<-", c("CommonFG", "character", "ANY"),
setMethod("[[<-", c("CommonFG", "character", "ANY"),
function(x, i, ..., value) {
if(length(i) > 1) {
stop("Only one path can be specified.")
Expand Down Expand Up @@ -129,3 +129,32 @@ setMethod( "h5unlink", signature(.Object="CommonFG", path="character"),
}, USE.NAMES = FALSE)
})

#' Deprecated CommonFG methods
#'
#' Since \code{obj[name]} is commonly used to get and set multiple elements,
#' \code{obj[[name]]} is the better fit for setting or retrieving a single dataset or groups.
#'
#' @param x,i,j,drop,value,... See \code{\link{CommonFG}}
#'
#' @name h5-deprecated
#' @rdname h5-deprecated
#' @export
setMethod("[", c("CommonFG", "character", "ANY"),
function(x, i, ..., drop=TRUE) {
var <- deparse(substitute(x))
key <- deparse(substitute(i))
.Deprecated("[[", msg = sprintf("Use %s[[%s]] instead of %s[%s]", var, key, var, key))
x[[i, ..., drop = drop]]
})

#' @rdname h5-deprecated
#' @export
setMethod("[<-", c("CommonFG", "character", "ANY"),
function(x, i, ..., value) {
# deparse(substitute(x)) sadly returns '*tmp*'
key <- deparse(substitute(i))
val <- deparse(substitute(value))
.Deprecated("[[<-", msg = sprintf("Use x[[%s]] <- %s instead of x[%s] <- %s", key, val, key, val))
x[[i, ...]] <- value
x
})
4 changes: 2 additions & 2 deletions R/Dataset-Subset.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
#' # Write submatrix to sub-region of DataSet
#' testmat_n <- matrix(as.integer(1:90), ncol = 9)
#' file <- h5file("test.h5", "a")
#' file["testgroup/testmat_n2"] <- testmat_n
#' file[["testgroup/testmat_n2"]] <- testmat_n
#' submat <- matrix(-1L:-9L, nrow = 3)
#' dset2 <- file["testgroup/testmat_n2"]
#' dset2 <- file[["testgroup/testmat_n2"]]
#' dset2[c(1, 3, 5), c(1, 3, 5)] <- submat
#' h5close(dset2)
#' h5close(file)
Expand Down
12 changes: 6 additions & 6 deletions R/H5File.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,25 @@
#' # The following examples generates a HDF5 file with the different HDF5
#' # Objects and shows its contents:
#' file <- h5file(name = "test1.h5", mode = "a")
#' file["testdataset"] <- 1:10
#' file[["testdataset"]] <- 1:10
#' h5attr(file, "testattrib") <- LETTERS[1:10]
#' file["testgroup/testdataset2"] <- 1:10
#' file[["testgroup/testdataset2"]] <- 1:10
#' file
#' # Close file and delete
#' h5close(file)
#' if(file.exists("test.h5")) file.remove("test.h5")
#'
#' # The following example shows hdf5 file contents and how to use them to iterate over HDF5 elements:
#' file <- h5file(name = "test2.h5", mode = "a")
#' file["testgroup1/testset1"] <- 1:10
#' file["testgroup2/testset2"] <- 11:20
#' file["testgroup3/testset3"] <- 21:30
#' file[["testgroup1/testset1"]] <- 1:10
#' file[["testgroup2/testset2"]] <- 11:20
#' file[["testgroup3/testset3"]] <- 21:30
#'
#' # Extract first 3 elements from each dataset and combine result to matrix
#' sapply(list.datasets(file, recursive = TRUE), function(x) file[x][1:3])
#' # Add new dataset to each group in HDF5 file
#' for(g in list.groups(file)) {
#' file[paste(g, "testsetx", collapse = "/")] <- 1:10
#' file[[paste(g, "testsetx", collapse = "/")]] <- 1:10
#' }
#' list.datasets(file, recursive = TRUE)
#' # Close file
Expand Down
4 changes: 2 additions & 2 deletions R/H5Location-Attribute.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
#' # Write Attributes for H5File, H5Group and DataSet
#' file <- h5file("test.h5")
#' h5attr(file, "fileattrib") <- 1:10
#' group <- file["testgroup"]
#' group <- file[["testgroup"]]
#' h5attr(group, "groupattrib") <- matrix(1:9, nrow = 3)
#' h5attr(group, "groupattrib")
#' group["testdataset"] <- 1:10
#' dset <- group["testdataset"]
#' dset <- group[["testdataset"]]
#' h5attr(dset, "dsetattrib") <- LETTERS[1:10]
#' h5close(dset)
#' h5close(group)
Expand Down
6 changes: 3 additions & 3 deletions R/h5-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@
#' mat <- matrix(1:9, nrow = 3)
#' rownames(mat) <- LETTERS[1:3]
#' colnames(mat) <- c("A", "BE", "BUU")
#' file["test/testmat/testmat"] <- mat
#' file[["test/testmat/testmat"]] <- mat
#' # Store numeric array in group '/test' and dataset 'testarray'
#' file["test/testarray"] <- array(as.numeric(1:45), dim = c(3, 3, 5))
#' file[["test/testarray"]] <- array(as.numeric(1:45), dim = c(3, 3, 5))
#'
#' # 3. Store rownames and column names of matrix as attributes
#' # Get created data set as object
#' dset <- file["test/testmat/testmat"]
#' dset <- file[["test/testmat/testmat"]]
#' # Store rownames in attribute 'dimnames_1'
#' h5attr(dset, "dimnames_1") <- rownames(mat)
#' # Store columnnames in attribute 'dimnames_2'
Expand Down
26 changes: 13 additions & 13 deletions man/CommonFG.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/DataSet-Subset.Rd

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

12 changes: 6 additions & 6 deletions man/H5File.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/H5Location-Attribute.Rd

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

19 changes: 19 additions & 0 deletions man/h5-deprecated.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/h5-package.Rd

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