Closed WillemSleegers closed 6 years ago
Is the below too hacky?
add_descriptives_overwrite <- function (descriptives, list, identifier = NULL, description = NULL, overwrite = F)
{
if (is.null(identifier)) {
identifier <- paste0("D", formatC(length(list) + 1, width = "1",
format = "d"))
}
else {
if (identifier %in% names(list)) {
stop("Identifier already exists.")
}
}
output <- tidy_descriptives(descriptives)
if (!is.null(description)) {
output$description <- description
}
if(overwrite){
list[[identifier]] <- NULL
}
list[[identifier]] <- output
return(list)
}
Actually, I'm not yet sure whether it's a good idea. You can just remove the element from the list by saying results$identifier <- NULL.
It's probably a good idea to be a bit annoying when it comes to saving your stats results.
Also, I am imagining that you will only start creating your results list after you are done with the data analysis, so you should know what you want to add.
Also, that code wouldn’t work because it would stop before you get to the overwrite part thanks to the identifier check at the beginning.
Closing this for now as I'm not sure whether it's a needed feature, but feel free to reopen if it's desired!
Maybe include an argument overwrite (default = F) wether
add_descriptive()
should overwrite the descriptives already in the list under that identifier?