@@ -39,7 +39,6 @@ feed_quality <- function(para) {
3939
4040 livestock_type_selected <- livestock_df [livestock_df $ livetype_code == livestock , ]
4141
42-
4342 for (season in 1 : nrow(seasons )) {
4443
4544 feed_production <- unnest(para [[" feed_items" ]], cols = c(feed_type_name ))
@@ -49,9 +48,7 @@ feed_quality <- function(para) {
4948 feed_allocation <- list ()
5049
5150 for (i in 1 : length(feed_types )) {
52-
53- feed_selected <- feed_production %> % dplyr :: filter(feed_type_name %in%
54- feed_production $ feed_type_name [i ])
51+ feed_selected <- feed_production %> % dplyr :: filter(feed_type_name %in% feed_types [i ])
5552
5653 # feed_item <- as.data.frame(feed_selected[["feed_items"]])
5754
@@ -77,7 +74,7 @@ feed_quality <- function(para) {
7774 seasons $ season_name [season ])
7875
7976 feed_item_selected <- feeding_seasons %> %
80- dplyr :: filter(feed_item_code == feed_selected [[" feed_item_code" ]])
77+ dplyr :: filter(feed_item_code %in% feed_selected [[" feed_item_code" ]])
8178
8279 livestock_selected <- feed_item_selected [[" livestock" ]] %> %
8380 as.data.frame() %> %
@@ -135,7 +132,7 @@ feed_quality <- function(para) {
135132 feed_allocation_all [is.na(feed_allocation_all )] <- 0
136133
137134 # Bind and add into the season list
138- season_allocation [[season ]] <- cbind(season_name = rep(feed_item_selected $ season_name , times = nrow(feed_allocation_all )),
135+ season_allocation [[season ]] <- cbind(season_name = rep(feed_item_selected $ season_name [ 1 ], times = nrow(feed_allocation_all )),
139136 livestock_category_code = rep(livestock_selected $ livetype_code , times = nrow(feed_allocation_all )),
140137 livestock_category_name = rep(livestock_type_selected $ livetype_desc , times = nrow(feed_allocation_all )),
141138 feed_allocation_all )
@@ -155,4 +152,6 @@ feed_quality <- function(para) {
155152 # Bind by rows
156153 livestock_feed_allocation <- livestock_allocation %> % bind_rows()
157154
155+ return (livestock_feed_allocation )
156+
158157}
0 commit comments