Why use pipeable operator in function?

# Write a function to convert bushels to kg
bushels_to_kgs <- function(bushels, crop) {
  bushels %>%
    # Convert bushels to lbs for this crop
    bushels_to_lbs(crop) %>%
    # Convert lbs to kgs
    lbs_to_kgs()
}

bushels has already been set in the argument of function. Why in the second line, we write bushels agin?

It has little sense to specify an argument and not using it (?)

You should not confuse this with the construction

bushels %>%
  bushels

Hey Tung,

The bushels argument within function() is more of an input than anything else. This is where you would enter your number of bushels when you call the bushels_to_kg() later on.

The second line mention of "bushels" is (for this function example) simply where your input entry from earlier fits within the pipeline ('%>%') that you've captured with this function. The "second line" is putting your entry to use.

Hope this helps

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.