Approaches to solving problems

  1. Understand the problem.
    • Identify inputs and outputs.
      • Input = Portal surveys csv
      • Output = plot of yearly abundance for large and small rodents
     # Overall goal: visualize how many large (>50g) and 
     # small (<50g) mammals are collected each year
    
  2. Break the problem down into a few pieces.
    • Bullet list on paper or comments in script.
     # Subtasks
         # Import data
         # Get column of small and large categories
         # Count number of each per year
         # Plot this
    
  3. Break those pieces into codeable chunks.

     # TODO: function that returns size class from weight
    
  4. Code one chunk at a time.

Coding one chunk

get_size_class()
if(weight > 50){
  size_class <- "large"
} else {
  size_class <- "small"
}
weight <- 10
get_size_class <- function(weight){
  if(weight > 50){
    size_class <- "large"
  } else {
    size_class <- "small"
  }
}
get_size_class(100)
get_size_class <- function(weight){
  if(weight > 50){
    size_class <- "large"
  } else {
    size_class <- "small"
  }
  return(size_class)
}
get_size_class <- function(weight, threshold){
  if(weight > threshold){
    size_class <- "large"
  } else {
    size_class <- "small"
  }
  return(size_class)
}
get_size_class(100, 50)
get_size_class(100, 150)

Rest of code in decomposition-example.R.