Function working when ran internally line-by-line, but not when ran as the function. Using HDF5r.

Hello all, I am trying to take some data frames I have created and use them to populate an HDF5/H5 file I can export to pass to some Python workflows. For some reason, this code works when I run it internally, line-by-line, but when I create the function it fails. This should output an h5 file with one group named "events", events will have 349 objects of size 1X6001 and 34 attributes.

Data

Function

make_trainer_hdf5(h5_file_path = "<path_where_you_want_to_create_H5_file>",
                  attirbutes = attributes,
                  signal = STEAD_data)

Error when ran as a function

Error: object of type 'builtin' is not subsettable
Called from: furrr_map2_template(x = .x, y = .y, fn = .f, dots = list(...), 
    options = .options, progress = .progress, type = "list", 
    map_fn = purrr::map2, env_globals = .env_globals)

Function Inner Workings

# not sure how to reference specific functions from this library so the entire package is passed
library(hdf5r)
# used importFrom dplyr %>% in actual function
library(dplyr)
# parellel process with future to speed up the function, it can take a while otherwise.
# I plan to put progress bars in the furrr function to keep better track of function progress later
library(future)

# may need to use multisession if multicore doesn't work. I hear it can be touchy with which OS is being used.
plan(multicore)

make_trainer_hdf5 <- function(h5_file_path, attirbutes, signal){

  NMTSO_trainer.h5 <- H5File$new(filename = sprintf("%s/NMTSO_trainer.h5", h5_file_path), mode = "w")

  event.grp <- NMTSO_trainer.h5$create_group("event")

  x = list()
  for (i in 1:length(signal$sac_EV)){
  x[[i]] <- signal$sac_EV[i] %>% unlist() %>% matrix(nrow = 1)
}

  rm(i)

  furrr::future_map2(attributes$trace_name, x,function(trace_name, x){
    event.grp[[trace_name]] <- x
  })

  rm(x)

  col_names <- colnames(attributes)

  info <- tidyr::expand_grid(trace_name = attributes$trace_name, col_names) %>%
    dplyr::mutate(value = furrr::future_map2(trace_name, col_names, function(x, y){
      dplyr::pull(attributes[attributes$trace_name == x, y])
    }))

  info <- info[-c(which(info$col_names == "trace_name")),]

  furrr::future_pwalk(as.list(info), function(trace_name, col_names, value){
    h5attr(event.grp[[trace_name]], col_names) <- value
  })

  rm(col_names)

  rm(info)

  NMTSO_trainer.h5$close_all()
}

You are inconsistent in how you spell attributes/attirbutes

Oof.... that's embarrassing. Thank you so much. I get so steeped in what I think should happen I look right over the discrepancies like that.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.