UtrechtUniversity / workshop-computational-reproducibility

Material for the workshop 'Best Practices for Writing Reproducible Code'
https://utrechtuniversity.github.io/workshop-computational-reproducibility/
Other
9 stars 13 forks source link

docstring example #67

Open nehamoopen opened 6 months ago

nehamoopen commented 6 months ago

We can initially provide the function without comments, so they can try it out easily.

library(docstring)

even_or_odd <- function(number){
  #' @title Test If Even Or Odd
  #' @description This function takes one 
  #' input number and tests
  #' whether it's divisible by 2. It returns the number class 
  #' specifying whether it's even or odd.
  #' @param number The number to be tested
  #' @return Prints 'even' or 'odd'
  if(number%%2 == 0){
    number_class <- "even"
  } else{
    number_class <- "odd"
  }
  return(number_class)
}
nehamoopen commented 6 months ago

The multiply example a bit too simple and it's nice to have an example ready to go when teaching...