knitr::opts_chunk$set(echo = TRUE)

Introduction

This vignette provides an introduction to the croptimizer package with a short walk through the functions use or a typical croptimizing exercise.

Croptimize

Most users will want to use the high-level croptimize() function. This will accept arguments for the season, the day of the season, the fertilizer or Speed-Gro used, etc. and return a data.frame of possible crops sorted by net profit.

For example, we can get the optimal crops to plan on the first day of spring in your first year. There are various useful datapoints in the returned data.frame, but we can just focus on the name of the crop and the net profit for now.

croptimized_data <- croptimize(season = "spring", day_of_season = 1)
head(croptimized_data %>% dplyr::select(name, net_profit))

You can also provide what farming level you are (which affects probabilities of higher quality crops, and therefore of the expected net profit), as well as if you took the Tiller specialization at level 5.

croptimized_data <- 
  croptimize(season = "summer",
             day_of_season = 20,
             farming_level = 7,
             level_5_tiller = TRUE)
head(croptimized_data %>% dplyr::select(name, net_profit))

If you have applied fertilizer or Speed-Gro to your crops, you can provide that with soil_mods parameter. If you provide a single value for soil_mods, it will be used for all of your crops.

croptimized_data <- 
  croptimize(soil_mods = "Quality Fertilizer",
             season = "fall",
             day_of_season = 1,
             farming_level = 7,
             level_5_tiller = TRUE)
head(croptimized_data %>% dplyr::select(name, net_profit))

If you provide a named vector, this will assign different soil modifiers to different crops, but you do have to use the same modifier for each crop (e.g. the current version of this package will not allow you to use Quality Fertilizer for some Blueberry plants and Speed-Gro for other Blueberry plants).

croptimized_data_2 <- 
  croptimize(soil_mods = c("Ancient Fruit" = "Quality Fertilizer",
                           "Fairy Rose" = "Quality Fertilizer",
                           "Artichoke" = "Quality Fertilizer",
                           "Yam" = "Quality Fertilizer",
                           "Amaranth" = "Quality Fertilizer",
                           "Beet" = "Quality Fertilizer",
                           "Eggplant" = "Quality Fertilizer",
                           "Bok Choy" = "Quality Fertilizer",
                           "Grape" = "Quality Fertilizer",
                           "Wheat" = "Quality Fertilizer",
                           "Sunflower" = "Quality Fertilizer",
                           "Cranberries" = "Quality Fertilizer",
                           "Corn" = "Quality Fertilizer"),
             season = "fall",
             day_of_season = 1,
             farming_level = 7,
             level_5_tiller = TRUE)
head(croptimized_data_2 %>% dplyr::select(name, net_profit))

Crop data

Typically, you will start with the crop data stored in the package as croptimizer::crops, although you are free to use your own data so long as columns have the same names and data type.

head(croptimizer::crops)

Calculate base seed price

The first step is to calculate the cost of the seeds, which will depend on if you have a JojaMart membership or not. The drop_cols parameter determines if intermediate columns used in calculating the base seed price should be preserved in the output or not. If you would find these columns useful, then use drop_cols = TRUE.

croptimized_data <-
  croptimizer::crops %>%
  calc_seed_prices(joja_member = FALSE, drop_cols = TRUE)
croptimized_data_with_extra_cols <-
  croptimizer::crops %>%
  calc_seed_prices(joja_member = FALSE, drop_cols = FALSE)
setdiff(colnames(croptimized_data_with_extra_cols),
        colnames(croptimized_data))

Append the Soil Modification

Soil modifications are appended to introduce effects for fertilizers and/or Speed-Gro. There are several ways to provide a soil_mods argument.

One way to provide the soil mod argument is via a singleton character. In this case, it will be replicated for the number of rows of the dataset.

croptimized_data <-
  croptimized_data %>%
  append_soil_mod(soil_mods = "Quality Fertilizer") %>%
  filter_to_season(season = "fall") %>%
  filter_to_days(day_of_season = 1) %>% 
  calc_crop_sale_price()
table(croptimized_data$soil_mod)

If no soil mod is supplied, then "Normal" is repeated for the number of rows of the data.

croptimized_data <-
  croptimized_data %>%
  append_soil_mod()
table(croptimized_data$soil_mod)

If an unnamed vector of appropriate length is provided, then it will be simply appended to the dataset.

croptimized_data <-
  croptimized_data %>%
  append_soil_mod(soil_mods = c(rep("Quality Fertilizer", 18),
                                rep("Deluxe Fertilizer", 18)))
table(croptimized_data$soil_mod)

Finally, if a named vector of any length is provided, then it will join to the crop data on those names, and any resulting NA's for soil mod will be filled with "Normal."

croptimized_data <-
  croptimized_data %>%
  append_soil_mod(soil_mods = c("Potato" = "Quality Fertilizer",
                                "Blueberry" = "Speed-Gro"))
table(croptimized_data$soil_mod)

Filter to Seasons and Days

Next, we need to filter to crops that grow in this season, and crops that have sufficient time to finish growing before the end of the season.

croptimized_data <-
  croptimized_data %>%
  filter_to_season(season = "spring") %>%
  filter_to_days(day_of_season = 1)

Calculate the Sale Price of the Crop

croptimized_data <-
  croptimized_data %>%
  calc_crop_sale_price(farming_level = 5, level_5_tiller = TRUE)

Calculate Net Profit

croptimized_data <-
  croptimized_data %>%
  calc_net_profit()


aftonsteps/croptimizer documentation built on Jan. 28, 2021, 12:50 p.m.