Skip to content
Snippets Groups Projects
Commit c12f78f1 authored by dj44vuri's avatar dj44vuri
Browse files

improvements to chunks and save as qs instead of RDS

parent f19ba60f
Branches
Tags
No related merge requests found
...@@ -29,7 +29,8 @@ Imports: ...@@ -29,7 +29,8 @@ Imports:
tidyr, tidyr,
rlang, rlang,
future, future,
furrr furrr,
qs
Suggests: Suggests:
knitr, knitr,
testthat (>= 3.0.0) testthat (>= 3.0.0)
......
...@@ -86,6 +86,9 @@ designs_all <- list() ...@@ -86,6 +86,9 @@ designs_all <- list()
design<- readdesign(design = designfile, designtype = designtype, destype = destype) design<- readdesign(design = designfile, designtype = designtype, destype = destype)
dname <- designname <- stringr::str_remove_all(designfile, "(.ngd|_|.RDS)")
if (!("Block" %in% colnames(design))) design$Block=1 # If no Blocks exist, create a variable Blocks to indicate it is only one block if (!("Block" %in% colnames(design))) design$Block=1 # If no Blocks exist, create a variable Blocks to indicate it is only one block
nsets<-nrow(design) nsets<-nrow(design)
...@@ -243,8 +246,9 @@ transform_util2 <- function() { ...@@ -243,8 +246,9 @@ transform_util2 <- function() {
) )
tictoc::toc() tictoc::toc()
chunkfilename <- paste0(dname,"_tmp_",i,".qs")
saveRDS(output,paste0("tmp_",i,".RDS")) qs::qsave(output,chunkfilename,preset = "fast")
rm(output) rm(output)
gc() gc()
...@@ -265,8 +269,8 @@ transform_util2 <- function() { ...@@ -265,8 +269,8 @@ transform_util2 <- function() {
# Assuming the files are named in sequence as 'tmp_1.RDS', 'tmp_2.RDS', ..., 'tmp_n.RDS' # Assuming the files are named in sequence as 'tmp_1.RDS', 'tmp_2.RDS', ..., 'tmp_n.RDS'
for (i in 1:chunks) { for (i in 1:chunks) {
# Load each RDS file # Load each RDS file
file_content <- readRDS(paste0("tmp_", i, ".RDS")) file_content <- qs::qread(chunkfilename)
file.remove(paste0("tmp_", i, ".RDS")) file.remove(chunkfilename)
# Append the contents of each file to the all_outputs list # Append the contents of each file to the all_outputs list
output <- c(output, file_content) output <- c(output, file_content)
...@@ -318,7 +322,7 @@ tictoc::toc() ...@@ -318,7 +322,7 @@ tictoc::toc()
return(output) return(output)
} else { } else { # if estimate not TRUE, return only simulated data.
return(sim_data) return(sim_data)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment