R studio: error gather function

#Change from wide format to long format

oil_consumption_per_cap <- gather(oil_consumption_per_cap, 'Year', 'Consumption',
2:length(oil_consumption_per_cap))

Error in gather(oil_consumption_per_cap, "Year", "Consumption", 2:length(oil_consumption_per_cap)) :
could not find function "gather"

why does it appear error?

This suggests you haven't loaded the tidyr package

library(tidyr)

If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.