jengavignette.Rmd
Great, you’ve decided to look into jenga! Although we won’t be playing a game, we can still have fun by making RData files a little easier to work with. Here is a typical example in which you may want to use a jenga stack.
library(jenga)
methods <- c("Method 1", "Method 2", "Method 3")
sims.1 <- create_stack(methods)
status_stack(sims.1)
##
## All slots are empty!
We can see that all slots are empty! Lets add some data to the slot. The default is to save the jenga stack to an RData file with the name of the stack. If you don’t want to save it, but rather only commit to memory, set save=FALSE
.
res <- c(1,2,3,4,5,6)
update_stack(stack=sims.1, objects = res, slots = "Method 1", save=FALSE)
##
## Jenga stack ` sims.1 ` has been updated for
## * Method 1
We can now check on the status of our jenga stack again:
status_stack(sims.1)
##
## Total of 1 slots filled out of 3 total slots
## -- Filled Slots --------------------------------------------------------------------------------------------------------------------------------------------------
## v Method 1
## -- Empty Slots ---------------------------------------------------------------------------------------------------------------------------------------------------
## x Method 2 x Method 3
We can also update more than one slot at a time. Suppose we now have data for Methods 2 and 3. We can combine the results into a list and update 2 slots at once.
res2 <- c(2,3,4,5,6,7)
res3 <- c(3,4,5,6,7,8)
res <- list(res2,res3)
update_stack(stack=sims.1, objects = res, slots =c("Method 2", "Method 3"), save=FALSE)
##
## Jenga stack ` sims.1 ` has been updated for
## * Method 2 * Method 3
If we check the status of the stack again, we will see now that it is all filled!
status_stack(sims.1)
##
## All slots are filled!
Say now that you want to extend the stack to hold a fourth method for your simulation study. We can easily add another slot using the extend_stack
function.
new.method <- "Method 4"
extend_stack(stack=sims.1, new.slot = new.method )
status_stack(sims.1)
##
## Total of 3 slots filled out of 4 total slots
## -- Filled Slots --------------------------------------------------------------------------------------------------------------------------------------------------
## v Method 1 v Method 3
## v Method 2
## -- Empty Slots ---------------------------------------------------------------------------------------------------------------------------------------------------
## x Method 4
If you want to merge jenga stacks, then we can use the merge_stack
function to make this easy.
new.stack <- merge_stack(sims.1, sims.2)