WillemSleegers / tidystats-v0.3

R package to produce a tidy output file of statistical models.
Other
22 stars 2 forks source link

Overwrite identifiers? #43

Closed WillemSleegers closed 6 years ago

WillemSleegers commented 7 years ago

Maybe include an argument overwrite (default = F) wether add_descriptive() should overwrite the descriptives already in the list under that identifier?

ghost commented 7 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)
}
WillemSleegers commented 7 years ago

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.

WillemSleegers commented 7 years ago

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.

WillemSleegers commented 6 years ago

Closing this for now as I'm not sure whether it's a needed feature, but feel free to reopen if it's desired!