Running 'testthat.R' [6s]
Running the tests in 'tests/testthat.R' failed.
Complete output:
  > library(testthat)
  > library(rbi)
  
  Attaching package: 'rbi'
  
  The following objects are masked from 'package:stats':
  
      filter, optimise
  
  The following object is masked from 'package:utils':
  
      fix
  
  The following object is masked from 'package:base':
  
      sample
  
  > 
  > test_check("rbi")
  -- 1. Error: (unknown) (@test-io.r#6)  -----------------------------------------
  The melt generic in data.table has been passed a array (not a data.table) but the reshape2 package is not installed to process this type. Please either install reshape2 and try again, or pass a data.table to melt instead.
  1: attach_file(bi, file = "init", bi_read(bi, vars = c("mu", "sigma"))) at testthat/test-io.r:6
  2: attach_file.libbi(bi, file = "init", bi_read(bi, vars = c("mu", "sigma")))
  3: bi_read(bi, vars = c("mu", "sigma"))
  4: data.table::data.table(data.table::melt(all_values, varnames = dim_var_names))
  5: data.table::melt(all_values, varnames = dim_var_names)
  6: tryCatch(getNamespace("reshape2"), error = function(e) stop("The melt generic in data.table has been passed a ", 
         class(data)[1L], " (not a data.table) but the reshape2 package is not installed to process this type. Please either install reshape2 and try again, or pass a data.table to melt instead."))
  7: tryCatchList(expr, classes, parentenv, handlers)
  8: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  9: value[[3L]](cond)
  10: stop("The melt generic in data.table has been passed a ", class(data)[1L], " (not a data.table) but the reshape2 package is not installed to process this type. Please either install reshape2 and try again, or pass a data.table to melt instead.")
  
  -- 2. Error: (unknown) (@test-libbi.r#36)  -------------------------------------
  undefined exports: %s!=%, %s!==%, %s+%, %s<%, %s<=%, %s==%, %s===%, %s>%, %s>=%, %stri!=%, %stri!==%, %stri+%, %stri<%, %stri<=%, %stri==%, %stri===%, %stri>%, %stri>=%, stri_datetime_add<-, stri_sub<-, stri_subset<-, stri_subset_charclass<-, stri_subset_coll<-, stri_subset_fixed<-, stri_subset_regex<-, stri_c, stri_c_list, stri_cmp, stri_cmp_eq, stri_cmp_equiv, stri_cmp_ge, stri_cmp_gt, stri_cmp_le, stri_cmp_lt, stri_cmp_neq, stri_cmp_nequiv, stri_compare, stri_conv, stri_count, stri_count_boundaries, stri_count_charclass, stri_count_coll, stri_count_fixed, stri_count_regex, stri_count_words, stri_datetime_add, stri_datetime_create, stri_datetime_fields, stri_datetime_format, stri_datetime_fstr, stri_datetime_now, stri_datetime_parse, stri_datetime_symbols, stri_detect, stri_detect_charclass, stri_detect_coll, stri_detect_fixed, stri_detect_regex, stri_dup, stri_duplicated, stri_duplicated_any, stri_enc_detect, stri_enc_detect2, stri_enc_fromutf32, stri_enc_get, stri_enc_info, stri_enc_isascii, stri_enc_isutf16be, stri_enc_isutf16le, stri_enc_isutf32be, stri_enc_isutf32le, stri_enc_isutf8, stri_enc_list, stri_enc_mark, stri_enc_set, stri_enc_toascii, stri_enc_tonative, stri_enc_toutf32, stri_enc_toutf8, stri_encode, stri_endswith, stri_endswith_charclass, stri_endswith_coll, stri_endswith_fixed, stri_escape_unicode, stri_extract, stri_extract_all, stri_extract_all_boundaries, stri_extract_all_charclass, stri_extract_all_coll, stri_extract_all_fixed, stri_extract_all_regex, stri_extract_all_words, stri_extract_first, stri_extract_first_boundaries, stri_extract_first_charclass, stri_extract_first_coll, stri_extract_first_fixed, stri_extract_first_regex, stri_extract_first_words, stri_extract_last, stri_extract_last_boundaries, stri_extract_last_charclass, stri_extract_last_coll, stri_extract_last_fixed, stri_extract_last_regex, stri_extract_last_words, stri_flatten, stri_info, stri_isempty, stri_join, stri_join_list, stri_length, stri_list2matrix, stri_locale_get, stri_locale_info, stri_locale_list, stri_locale_set, stri_locate, stri_locate_all, stri_locate_all_boundaries, stri_locate_all_charclass, stri_locate_all_coll, stri_locate_all_fixed, stri_locate_all_regex, stri_locate_all_words, stri_locate_first, stri_locate_first_boundaries, stri_locate_first_charclass, stri_locate_first_coll, stri_locate_first_fixed, stri_locate_first_regex, stri_locate_first_words, stri_locate_last, stri_locate_last_boundaries, stri_locate_last_charclass, stri_locate_last_coll, stri_locate_last_fixed, stri_locate_last_regex, stri_locate_last_words, stri_match, stri_match_all, stri_match_all_regex, stri_match_first, stri_match_first_regex, stri_match_last, stri_match_last_regex, stri_na2empty, stri_numbytes, stri_opts_brkiter, stri_opts_collator, stri_opts_fixed, stri_opts_regex, stri_order, stri_pad, stri_pad_both, stri_pad_left, stri_pad_right, stri_paste, stri_paste_list, stri_rand_lipsum, stri_rand_shuffle, stri_rand_strings, stri_read_lines, stri_read_raw, stri_remove_empty, stri_replace, stri_replace_all, stri_replace_all_charclass, stri_replace_all_coll, stri_replace_all_fixed, stri_replace_all_regex, stri_replace_first, stri_replace_first_charclass, stri_replace_first_coll, stri_replace_first_fixed, stri_replace_first_regex, stri_replace_last, stri_replace_last_charclass, stri_replace_last_coll, stri_replace_last_fixed, stri_replace_last_regex, stri_replace_na, stri_reverse, stri_sort, stri_split, stri_split_boundaries, stri_split_charclass, stri_split_coll, stri_split_fixed, stri_split_lines, stri_split_lines1, stri_split_regex, stri_startswith, stri_startswith_charclass, stri_startswith_coll, stri_startswith_fixed, stri_stats_general, stri_stats_latex, stri_sub, stri_subset, stri_subset_charclass, stri_subset_coll, stri_subset_fixed, stri_subset_regex, stri_timezone_get, stri_timezone_info, stri_timezone_list, stri_timezone_set, stri_trans_char, stri_trans_general, stri_trans_isnfc, stri_trans_isnfd, stri_trans_isnfkc, stri_trans_isnfkc_casefold, stri_trans_isnfkd, stri_trans_list, stri_trans_nfc, stri_trans_nfd, stri_trans_nfkc, stri_trans_nfkc_casefold, stri_trans_nfkd, stri_trans_tolower, stri_trans_totitle, stri_trans_toupper, stri_trim, stri_trim_both, stri_trim_left, stri_trim_right, stri_unescape_unicode, stri_unique, stri_width, stri_wrap, stri_write_lines
  1: bi_model(lines = stringi::stri_split_lines(model_str)[[1]]) at testthat/test-libbi.r:36
  2: stringi::stri_split_lines
  3: getExportedValue(pkg, name)
  4: asNamespace(ns)
  5: getNamespace(ns)
  6: tryCatch(loadNamespace(name), error = function(e) stop(e))
  7: tryCatchList(expr, classes, parentenv, handlers)
  8: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  9: value[[3L]](cond)
  
  -- 3. Error: we can extract a sample from an output file (@test-samples.r#8)  --
  The melt generic in data.table has been passed a matrix (not a data.table) but the reshape2 package is not installed to process this type. Please either install reshape2 and try again, or pass a data.table to melt instead.
  1: expect_true(nrow(extract_sample(example_output_file, 13)[["Z"]]) > 0) at testthat/test-samples.r:8
  2: quasi_label(enquo(object), label)
  3: eval_bare(get_expr(quo), get_env(quo))
  4: nrow(extract_sample(example_output_file, 13)[["Z"]])
  5: extract_sample(example_output_file, 13)
  6: do.call(bi_read, read_options)
  7: (function (x, vars, dims, model, type, file, missval.threshold, coord_dims, vector, 
         thin, verbose, clear_cache, init.to.param = FALSE) 
     {
         if (missing(file)) {
             nc <- bi_open(x)
         }
         else {
             nc <- bi_open(x, file)
         }
         res <- list()
         thin <- as.integer(ifelse(missing(thin), ifelse("libbi" %in% class(x), x$thin, 
             1), thin))
         legacy_coord_dims <- NA_character_
         if (missing(coord_dims)) {
             coord_dims <- NULL
         }
         else if (is.character(coord_dims)) {
             legacy_coord_dims <- coord_dims
             coord_dims <- list()
         }
         if ("libbi" %in% class(x) && !is.null(x$dims)) {
             if (missing(model)) {
                 model <- x$model
             }
             else {
                 stop("'model' should not be given if 'data' is a 'libbi' object'.")
             }
             if (missing(dims) || is.null(dims)) {
                 dims <- x$dims
             }
             else {
                 warning("Given 'dims' will overwrite dimensions in passed libbi object")
             }
             if (is.null(coord_dims)) {
                 coord_dims <- x$coord_dims
             }
             else {
                 warning("Given 'coord_dims' will overwrite dimensions in passed libbi object")
             }
         }
         all_nc_var_names <- unname(vapply(nc[["var"]], function(y) {
             y[["name"]]
         }, ""))
         time_coord_names <- c()
         nc_var_names <- list()
         arg_names <- names(as.list(match.call()[-1]))
         for (var_type in c("coord", "time")) {
             time_coord_names[var_type] <- ifelse(paste(var_type, "name", sep = "_") %in% 
                 arg_names, get(paste(var_type, "name", sep = "_")), var_type)
             nc_var_names[[var_type]] <- grep(paste0("^", var_type), all_nc_var_names, 
                 value = TRUE)
         }
         forbidden_names <- intersect(vapply(nc[["dim"]], function(y) {
             y[["name"]]
         }, ""), time_coord_names)
         if (length(forbidden_names) > 0) {
             stop("Can't have a dimension called ", paste(forbidden_names, sep = ", "), 
                 ".")
         }
         nc_var_names[["other"]] <- setdiff(all_nc_var_names, unlist(nc_var_names))
         if (!missing(vars) && !missing(type)) {
             stop("Only one of 'vars' and 'type' can be given.")
         }
         if (!missing(type)) {
             vars <- var_names(model, type, opt = TRUE)
             vars <- grep("has_output[^=]*=[^[0-1]*0", vars, value = TRUE, invert = TRUE)
             vars <- gsub("[[:space:]]*\\(.*$", "", vars)
         }
         if (!missing(vars)) {
             missing_vars <- setdiff(vars, nc_var_names[["other"]])
             if (length(missing_vars) > 0) {
                 if (all(vars %in% c(nc_var_names[["coord"]], nc_var_names[["time"]]))) {
                     nc_var_names[["coord"]] <- character(0)
                     nc_var_names[["time"]] <- character(0)
                     nc_var_names[["other"]] <- vars
                 }
                 else {
                     warning("Variable(s) ", missing_vars, " not found")
                 }
             }
             nc_var_names[["other"]] <- intersect(vars, nc_var_names[["other"]])
         }
         var_dims <- list()
         for (var_type in names(nc_var_names)) {
             var_dims[[var_type]] <- list()
             for (var_name in nc_var_names[[var_type]]) {
                 var <- nc[["var"]][[var_name]]
                 dim_names <- vapply(var$dim, function(y) {
                     y$name
                 }, "")
                 var_dims[[var_type]][[var_name]] <- dim_names[nchar(dim_names) > 0]
             }
         }
         res <- base::vector("list", length(nc_var_names[["other"]]))
         names(res) <- nc_var_names[["other"]]
         if ("libbi" %in% class(x) && x$use_cache && (missing(file) || file == "output")) {
             if (!missing(clear_cache) && clear_cache) {
                 x$.cache$data <- NULL
                 x$.cache$thin <- NULL
             }
             cached_other <- vapply(nc_var_names[["other"]], function(y) {
                 return(y %in% names(x$.cache$data) && thin == x$.cache$thin[y])
             }, TRUE)
         }
         else {
             cached_other <- rep(FALSE, length(nc_var_names[["other"]]))
         }
         for (var_name in nc_var_names[["other"]][cached_other]) {
             if (!missing(verbose) && verbose) {
                 message(date(), " ", var_name, " (cached)")
             }
             res[[var_name]] <- x$.cache$data[[var_name]]
         }
         for (var_name in nc_var_names[["other"]][!cached_other]) {
             if (!missing(verbose) && verbose) {
                 message(date(), " ", var_name)
             }
             if (missing(vars) || var_name %in% vars) {
                 dim_var_names <- var_dims[["other"]][[var_name]]
                 dim_lengths <- vapply(seq_along(dim_var_names), function(y) {
                     nc[["var"]][[var_name]][["dim"]][[y]][["len"]]
                 }, 0)
                 names(dim_lengths) <- dim_var_names
                 if ("np" %in% dim_var_names && thin > 1) {
                     np_indices <- seq(1, dim_lengths["np"], by = thin)
                     dim_lengths["np"] <- length(np_indices)
                     all_values <- array(dim = dim_lengths)
                     if (!missing(verbose) && verbose) 
                       pb <- txtProgressBar(min = 0, max = length(np_indices), char = ".", 
                         style = 1)
                     for (i in seq_along(np_indices)) {
                       dim_list <- lapply(dim_lengths, seq_len)
                       dim_list[["np"]] <- i
                       start_vec <- dim_lengths
                       start_vec[] <- 1
                       start_vec["np"] <- np_indices[i]
                       count_vec <- dim_lengths
                       count_vec["np"] <- 1
                       all_values <- do.call("[<-", c(list(all_values), unname(dim_list), 
                         list(ncvar_get(nc, var_name, start = start_vec, count = count_vec))))
                       if (!missing(verbose) && verbose) 
                         setTxtProgressBar(pb, i)
                     }
                     if (!missing(verbose) && verbose) 
                       close(pb)
                 }
                 else {
                     all_values <- ncvar_get(nc, var_name)
                 }
                 if ("np" %in% names(dim_lengths) && dim_lengths[["np"]] == 1) {
                     dim_lengths <- dim_lengths[names(dim_lengths) != "np"]
                     dim_var_names <- names(dim_lengths)
                 }
                 if (any(duplicated(dim_var_names))) {
                     duplicated_dim_names <- dim_var_names[duplicated(dim_names)]
                     for (dup_dim in duplicated_dim_names) {
                       dim_var_names[dim_var_names == dup_dim] <- paste(dup_dim, seq_along(dim_var_names[dim_var_names == 
                         dup_dim]), sep = ".")
                     }
                 }
                 if (length(dim_lengths) > 0) {
                     all_values <- array(all_values, dim = dim_lengths)
                 }
                 if (!is.null(dim(all_values))) {
                     mav <- data.table::data.table(data.table::melt(all_values, varnames = dim_var_names))
                     mav <- mav[, c(dim_var_names, "value"), with = F]
                     all_matching_dims <- c()
                     for (var_type in names(time_coord_names)) {
                       matching_dims <- unname(unlist(var_dims[[var_type]])[unlist(var_dims[[var_type]]) %in% 
                         dim_var_names])
                       matching_vars <- names(var_dims[[var_type]])[vapply(var_dims[[var_type]], 
                         function(x) {
                           any(x %in% dim_var_names)
                         }, TRUE)]
                       all_matching_dims <- union(all_matching_dims, matching_dims)
                       if (length(matching_vars) == 1) {
                         merge_values <- ncvar_get(nc, matching_vars)
                         if (var_type == "coord" && !is.null(coord_dims[[var_name]])) {
                           if (length(dim(merge_values)) == 1) {
                             merge_values <- data.table::data.table(coord = merge_values)
                           }
                           colnames(merge_values) <- coord_dims[[var_name]]
                           merge_values <- apply(merge_values, 2, as.integer)
                           mav <- cbind(merge_values, mav)
                         }
                         else {
                           mav_merge <- data.table::data.table(data.table::melt(merge_values, 
                             varnames = matching_dims, value.name = time_coord_names[var_type]))
                           mav <- merge(mav_merge, mav, by = unname(matching_dims))
                         }
                       }
                       else if (length(matching_vars) > 1) {
                         stop(paste0("Found multiple matching", var_type, " variables for ", 
                           var_name, ": ", matching_vars))
                       }
                     }
                     for (var in setdiff(all_matching_dims, "ns")) {
                       mav[[var]] <- NULL
                     }
                     table_order <- c(setdiff(colnames(mav), c(time_coord_names, "value")), 
                       intersect(colnames(mav), time_coord_names), "value")
                     mav <- mav[, table_order, with = FALSE]
                     cols <- setdiff(colnames(mav), "value")
                     if (length(cols) > 0) 
                       setkeyv(mav, cols)
                     rownames(mav) <- seq_len(nrow(mav))
                     if ("libbi" %in% class(x) && length(x$coord_dim) == 1 && "coord" %in% 
                       colnames(mav)) {
                       setnames(mav, "coord", x$coord_dim)
                     }
                     else if (!missing(dims) && !is.null(dims) && length(dims) == 1 && 
                       "coord" %in% colnames(mav)) {
                       setnames(mav, "coord", names(dims))
                     }
                     if ("libbi" %in% class(x) && length(x$time_dim) == 1 && "time" %in% 
                       colnames(mav)) {
                       setnames(mav, "time", x$time_dim)
                     }
                     for (col in colnames(mav)) {
                       if (!missing(dims) && !is.null(dims) && col %in% names(dims)) {
                         mav[[col]] <- factor(mav[[col]], labels = dims[[col]])
                       }
                       else if (col %in% var_dims[["other"]][[var_name]]) {
                         mav[[col]] <- mav[[col]] - 1
                       }
                     }
                 }
                 else {
                     mav <- all_values
                 }
                 if (!missing(missval.threshold)) {
                     if (data.table::is.data.table(mav)) {
                       missing.values <- which(mav$value > missval.threshold)
                       if (length(missing.values) > 0) {
                         mav[missing.values, ]$value <- NA_real_
                       }
                     }
                     else {
                       mav[mav > missval.threshold] <- NA_real_
                     }
                 }
                 if (!missing(vector) && vector) {
                     res[[var_name]] <- mav$value
                 }
                 else {
                     if (data.table::is.data.table(mav)) {
                       res[[var_name]] <- setDF(mav)
                     }
                     else {
                       res[[var_name]] <- mav
                     }
                 }
             }
         }
         if (any(class(x) %in% c("character", "libbi"))) 
             nc_close(nc)
         if ("libbi" %in% class(x) && x$use_cache && (missing(file) || file == "output")) {
             if (!("data" %in% names(x$.cache))) {
                 x$.cache$data <- list()
             }
             if (!("thin" %in% names(x$.cache))) {
                 x$.cache$thin <- list()
             }
             for (name in nc_var_names[["other"]][!cached_other]) {
                 x$.cache$data[[name]] <- res[[name]]
                 x$.cache$thin[[name]] <- thin
             }
         }
         if (init.to.param) {
             res <- lapply(res, function(x) {
                 if (is.data.frame(x) && "time" %in% colnames(x)) {
                     min_time <- min(x$time)
                     x <- x[x$time == min_time, ]
                     x$time <- NULL
                 }
                 x
             })
         }
         return(res)
     })(x = "D:/temp/RtmpoVnhFO/RLIBS_2fddc1a4f403e/rbi/example_output.nc")
  8: data.table::data.table(data.table::melt(all_values, varnames = dim_var_names))
  9: data.table::melt(all_values, varnames = dim_var_names)
  10: tryCatch(getNamespace("reshape2"), error = function(e) stop("The melt generic in data.table has been passed a ", 
         class(data)[1L], " (not a data.table) but the reshape2 package is not installed to process this type. Please either install reshape2 and try again, or pass a data.table to melt instead."))
  11: tryCatchList(expr, classes, parentenv, handlers)
  12: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  13: value[[3L]](cond)
  14: stop("The melt generic in data.table has been passed a ", class(data)[1L], " (not a data.table) but the reshape2 package is not installed to process this type. Please either install reshape2 and try again, or pass a data.table to melt instead.")
  
  -- 4. Error: we can get the traces of an output file (@test-samples.r#13)  -----
  The melt generic in data.table has been passed a array (not a data.table) but the reshape2 package is not installed to process this type. Please either install reshape2 and try again, or pass a data.table to melt instead.
  1: get_traces(example_output_file, model = model, burnin = 10) at testthat/test-samples.r:13
  2: do.call(bi_read, read_options)
  3: (function (x, vars, dims, model, type, file, missval.threshold, coord_dims, vector, 
         thin, verbose, clear_cache, init.to.param = FALSE) 
     {
         if (missing(file)) {
             nc <- bi_open(x)
         }
         else {
             nc <- bi_open(x, file)
         }
         res <- list()
         thin <- as.integer(ifelse(missing(thin), ifelse("libbi" %in% class(x), x$thin, 
             1), thin))
         legacy_coord_dims <- NA_character_
         if (missing(coord_dims)) {
             coord_dims <- NULL
         }
         else if (is.character(coord_dims)) {
             legacy_coord_dims <- coord_dims
             coord_dims <- list()
         }
         if ("libbi" %in% class(x) && !is.null(x$dims)) {
             if (missing(model)) {
                 model <- x$model
             }
             else {
                 stop("'model' should not be given if 'data' is a 'libbi' object'.")
             }
             if (missing(dims) || is.null(dims)) {
                 dims <- x$dims
             }
             else {
                 warning("Given 'dims' will overwrite dimensions in passed libbi object")
             }
             if (is.null(coord_dims)) {
                 coord_dims <- x$coord_dims
             }
             else {
                 warning("Given 'coord_dims' will overwrite dimensions in passed libbi object")
             }
         }
         all_nc_var_names <- unname(vapply(nc[["var"]], function(y) {
             y[["name"]]
         }, ""))
         time_coord_names <- c()
         nc_var_names <- list()
         arg_names <- names(as.list(match.call()[-1]))
         for (var_type in c("coord", "time")) {
             time_coord_names[var_type] <- ifelse(paste(var_type, "name", sep = "_") %in% 
                 arg_names, get(paste(var_type, "name", sep = "_")), var_type)
             nc_var_names[[var_type]] <- grep(paste0("^", var_type), all_nc_var_names, 
                 value = TRUE)
         }
         forbidden_names <- intersect(vapply(nc[["dim"]], function(y) {
             y[["name"]]
         }, ""), time_coord_names)
         if (length(forbidden_names) > 0) {
             stop("Can't have a dimension called ", paste(forbidden_names, sep = ", "), 
                 ".")
         }
         nc_var_names[["other"]] <- setdiff(all_nc_var_names, unlist(nc_var_names))
         if (!missing(vars) && !missing(type)) {
             stop("Only one of 'vars' and 'type' can be given.")
         }
         if (!missing(type)) {
             vars <- var_names(model, type, opt = TRUE)
             vars <- grep("has_output[^=]*=[^[0-1]*0", vars, value = TRUE, invert = TRUE)
             vars <- gsub("[[:space:]]*\\(.*$", "", vars)
         }
         if (!missing(vars)) {
             missing_vars <- setdiff(vars, nc_var_names[["other"]])
             if (length(missing_vars) > 0) {
                 if (all(vars %in% c(nc_var_names[["coord"]], nc_var_names[["time"]]))) {
                     nc_var_names[["coord"]] <- character(0)
                     nc_var_names[["time"]] <- character(0)
                     nc_var_names[["other"]] <- vars
                 }
                 else {
                     warning("Variable(s) ", missing_vars, " not found")
                 }
             }
             nc_var_names[["other"]] <- intersect(vars, nc_var_names[["other"]])
         }
         var_dims <- list()
         for (var_type in names(nc_var_names)) {
             var_dims[[var_type]] <- list()
             for (var_name in nc_var_names[[var_type]]) {
                 var <- nc[["var"]][[var_name]]
                 dim_names <- vapply(var$dim, function(y) {
                     y$name
                 }, "")
                 var_dims[[var_type]][[var_name]] <- dim_names[nchar(dim_names) > 0]
             }
         }
         res <- base::vector("list", length(nc_var_names[["other"]]))
         names(res) <- nc_var_names[["other"]]
         if ("libbi" %in% class(x) && x$use_cache && (missing(file) || file == "output")) {
             if (!missing(clear_cache) && clear_cache) {
                 x$.cache$data <- NULL
                 x$.cache$thin <- NULL
             }
             cached_other <- vapply(nc_var_names[["other"]], function(y) {
                 return(y %in% names(x$.cache$data) && thin == x$.cache$thin[y])
             }, TRUE)
         }
         else {
             cached_other <- rep(FALSE, length(nc_var_names[["other"]]))
         }
         for (var_name in nc_var_names[["other"]][cached_other]) {
             if (!missing(verbose) && verbose) {
                 message(date(), " ", var_name, " (cached)")
             }
             res[[var_name]] <- x$.cache$data[[var_name]]
         }
         for (var_name in nc_var_names[["other"]][!cached_other]) {
             if (!missing(verbose) && verbose) {
                 message(date(), " ", var_name)
             }
             if (missing(vars) || var_name %in% vars) {
                 dim_var_names <- var_dims[["other"]][[var_name]]
                 dim_lengths <- vapply(seq_along(dim_var_names), function(y) {
                     nc[["var"]][[var_name]][["dim"]][[y]][["len"]]
                 }, 0)
                 names(dim_lengths) <- dim_var_names
                 if ("np" %in% dim_var_names && thin > 1) {
                     np_indices <- seq(1, dim_lengths["np"], by = thin)
                     dim_lengths["np"] <- length(np_indices)
                     all_values <- array(dim = dim_lengths)
                     if (!missing(verbose) && verbose) 
                       pb <- txtProgressBar(min = 0, max = length(np_indices), char = ".", 
                         style = 1)
                     for (i in seq_along(np_indices)) {
                       dim_list <- lapply(dim_lengths, seq_len)
                       dim_list[["np"]] <- i
                       start_vec <- dim_lengths
                       start_vec[] <- 1
                       start_vec["np"] <- np_indices[i]
                       count_vec <- dim_lengths
                       count_vec["np"] <- 1
                       all_values <- do.call("[<-", c(list(all_values), unname(dim_list), 
                         list(ncvar_get(nc, var_name, start = start_vec, count = count_vec))))
                       if (!missing(verbose) && verbose) 
                         setTxtProgressBar(pb, i)
                     }
                     if (!missing(verbose) && verbose) 
                       close(pb)
                 }
                 else {
                     all_values <- ncvar_get(nc, var_name)
                 }
                 if ("np" %in% names(dim_lengths) && dim_lengths[["np"]] == 1) {
                     dim_lengths <- dim_lengths[names(dim_lengths) != "np"]
                     dim_var_names <- names(dim_lengths)
                 }
                 if (any(duplicated(dim_var_names))) {
                     duplicated_dim_names <- dim_var_names[duplicated(dim_names)]
                     for (dup_dim in duplicated_dim_names) {
                       dim_var_names[dim_var_names == dup_dim] <- paste(dup_dim, seq_along(dim_var_names[dim_var_names == 
                         dup_dim]), sep = ".")
                     }
                 }
                 if (length(dim_lengths) > 0) {
                     all_values <- array(all_values, dim = dim_lengths)
                 }
                 if (!is.null(dim(all_values))) {
                     mav <- data.table::data.table(data.table::melt(all_values, varnames = dim_var_names))
                     mav <- mav[, c(dim_var_names, "value"), with = F]
                     all_matching_dims <- c()
                     for (var_type in names(time_coord_names)) {
                       matching_dims <- unname(unlist(var_dims[[var_type]])[unlist(var_dims[[var_type]]) %in% 
                         dim_var_names])
                       matching_vars <- names(var_dims[[var_type]])[vapply(var_dims[[var_type]], 
                         function(x) {
                           any(x %in% dim_var_names)
                         }, TRUE)]
                       all_matching_dims <- union(all_matching_dims, matching_dims)
                       if (length(matching_vars) == 1) {
                         merge_values <- ncvar_get(nc, matching_vars)
                         if (var_type == "coord" && !is.null(coord_dims[[var_name]])) {
                           if (length(dim(merge_values)) == 1) {
                             merge_values <- data.table::data.table(coord = merge_values)
                           }
                           colnames(merge_values) <- coord_dims[[var_name]]
                           merge_values <- apply(merge_values, 2, as.integer)
                           mav <- cbind(merge_values, mav)
                         }
                         else {
                           mav_merge <- data.table::data.table(data.table::melt(merge_values, 
                             varnames = matching_dims, value.name = time_coord_names[var_type]))
                           mav <- merge(mav_merge, mav, by = unname(matching_dims))
                         }
                       }
                       else if (length(matching_vars) > 1) {
                         stop(paste0("Found multiple matching", var_type, " variables for ", 
                           var_name, ": ", matching_vars))
                       }
                     }
                     for (var in setdiff(all_matching_dims, "ns")) {
                       mav[[var]] <- NULL
                     }
                     table_order <- c(setdiff(colnames(mav), c(time_coord_names, "value")), 
                       intersect(colnames(mav), time_coord_names), "value")
                     mav <- mav[, table_order, with = FALSE]
                     cols <- setdiff(colnames(mav), "value")
                     if (length(cols) > 0) 
                       setkeyv(mav, cols)
                     rownames(mav) <- seq_len(nrow(mav))
                     if ("libbi" %in% class(x) && length(x$coord_dim) == 1 && "coord" %in% 
                       colnames(mav)) {
                       setnames(mav, "coord", x$coord_dim)
                     }
                     else if (!missing(dims) && !is.null(dims) && length(dims) == 1 && 
                       "coord" %in% colnames(mav)) {
                       setnames(mav, "coord", names(dims))
                     }
                     if ("libbi" %in% class(x) && length(x$time_dim) == 1 && "time" %in% 
                       colnames(mav)) {
                       setnames(mav, "time", x$time_dim)
                     }
                     for (col in colnames(mav)) {
                       if (!missing(dims) && !is.null(dims) && col %in% names(dims)) {
                         mav[[col]] <- factor(mav[[col]], labels = dims[[col]])
                       }
                       else if (col %in% var_dims[["other"]][[var_name]]) {
                         mav[[col]] <- mav[[col]] - 1
                       }
                     }
                 }
                 else {
                     mav <- all_values
                 }
                 if (!missing(missval.threshold)) {
                     if (data.table::is.data.table(mav)) {
                       missing.values <- which(mav$value > missval.threshold)
                       if (length(missing.values) > 0) {
                         mav[missing.values, ]$value <- NA_real_
                       }
                     }
                     else {
                       mav[mav > missval.threshold] <- NA_real_
                     }
                 }
                 if (!missing(vector) && vector) {
                     res[[var_name]] <- mav$value
                 }
                 else {
                     if (data.table::is.data.table(mav)) {
                       res[[var_name]] <- setDF(mav)
                     }
                     else {
                       res[[var_name]] <- mav
                     }
                 }
             }
         }
         if (any(class(x) %in% c("character", "libbi"))) 
             nc_close(nc)
         if ("libbi" %in% class(x) && x$use_cache && (missing(file) || file == "output")) {
             if (!("data" %in% names(x$.cache))) {
                 x$.cache$data <- list()
             }
             if (!("thin" %in% names(x$.cache))) {
                 x$.cache$thin <- list()
             }
             for (name in nc_var_names[["other"]][!cached_other]) {
                 x$.cache$data[[name]] <- res[[name]]
                 x$.cache$thin[[name]] <- thin
             }
         }
         if (init.to.param) {
             res <- lapply(res, function(x) {
                 if (is.data.frame(x) && "time" %in% colnames(x)) {
                     min_time <- min(x$time)
                     x <- x[x$time == min_time, ]
                     x$time <- NULL
                 }
                 x
             })
         }
         return(res)
     })(x = "D:/temp/RtmpoVnhFO/RLIBS_2fddc1a4f403e/rbi/example_output.nc", model = structure(c("model PZ {", 
     "const c = 0.25", "const e = 0.3", "const m_l = 0.1", "const m_q = 0.1", "param mu, sigma", 
     "state P, Z", "noise alpha", "obs P_obs", "sub parameter {", "mu ~ uniform(0.0, 1.0)", 
     "sigma ~ uniform(0.0, 0.5)", "}", "sub proposal_parameter {", "mu ~ gaussian(mu, 0.02)", 
     "sigma ~ gaussian(sigma, 0.01)", "}", "sub initial {", "P ~ log_normal(log(2.0), 0.2)", 
     "Z ~ log_normal(log(2.0), 0.1)", "}", "sub transition(delta = 1.0) {", "alpha ~ gaussian(mu, sigma)", 
     "ode {", "dP/dt = alpha*P - c*P*Z", "dZ/dt = e*c*P*Z - m_l*Z - m_q*Z*Z", "}", "}", 
     "sub observation {", "P_obs ~ log_normal(log(P), 0.2)", "}", "}"), class = "bi_model"), 
         type = "param")
  4: data.table::data.table(data.table::melt(all_values, varnames = dim_var_names))
  5: data.table::melt(all_values, varnames = dim_var_names)
  6: tryCatch(getNamespace("reshape2"), error = function(e) stop("The melt generic in data.table has been passed a ", 
         class(data)[1L], " (not a data.table) but the reshape2 package is not installed to process this type. Please either install reshape2 and try again, or pass a data.table to melt instead."))
  7: tryCatchList(expr, classes, parentenv, handlers)
  8: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  9: value[[3L]](cond)
  10: stop("The melt generic in data.table has been passed a ", class(data)[1L], " (not a data.table) but the reshape2 package is not installed to process this type. Please either install reshape2 and try again, or pass a data.table to melt instead.")
  
  == testthat results  ===========================================================
  OK: 24 SKIPPED: 0 FAILED: 4
  1. Error: (unknown) (@test-io.r#6) 
  2. Error: (unknown) (@test-libbi.r#36) 
  3. Error: we can extract a sample from an output file (@test-samples.r#8) 
  4. Error: we can get the traces of an output file (@test-samples.r#13) 
  
  Error: testthat unit tests failed
  Execution halted