knitr::opts_chunk$set(echo = TRUE) library(tidyverse) library(devtools) library(roxygen2) library(usethis) library(testthat)
# load the data temp <- read_csv("temp.csv") rain <- read_csv("precipitation.csv")
source('R/calc_extreme_temp_anom.R') source('R/calc_extreme_rain_anom.R') calc_extreme_temp_anom(temp) calc_extreme_rain_anom(rain)
Note to self: How to make set up testing on a new package - library(usethis) - usethis::use_test() - usethis::use_test("function")
#create some fake climate data #springtime mean temperatures by date and location crop_temp = rnorm(500, mean = 16 , sd = 2) dates = seq(from = 1920, to = 2010, by = 10) locations = c("SB", "LA", "SF","SLO","SD") ca_temp <- matrix(crop_temp, nrow = 10, ncol = 5, dimnames = list(c(dates), c(locations))) crop_rain = rnorm(500, mean = 10 , sd = 4) dates = seq(from = 1920, to = 2010, by = 10) locations = c("SB", "LA", "SF","SLO","SD") ca_rain <- matrix(crop_rain, nrow = 10, ncol = 5, dimnames = list(c(dates), c(locations)))
source('R/calc_crop_harvest.R') calc_crop_harvest(ca_temp, 15, .5)
source('R/calc_crop_harvest.R') source('R/calc_crop_cost.R') calc_crop_harvest(ca_temp, 15,.5) calc_crop_cost(ca_rain, 10, .5, 1000, 1.50)
for (i in 1:nrow(temp)) {temp$av[i] = mean(temp$Value[i] + temp$Value[i-1] + temp$Value[i+1])} temp2 = temp %>% mutate("index" = av*0.5) %>% mutate("condition" = ifelse(temp2$index>80, "drought","normal")) year_drought <- temp2 %>% filter(Date == 1960) source('R/calc_if_drought.R') calc_if_drought(temp, 0.5, 80, 2000) class(temp$Date)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.