I am using R to create an API request for data from a website and, as you can see from below, there is a lot of repetition in my code. This is created by the limitations of the site's API.
I would like to create a loop where the content of the text iterates through the years in the first text string and automatically creates Df1 through Df5. Then, passing this string through command1, then command2 but without those repetitions, too.
Hopefully, the question is clear and you can help
Thanks :)
Df1 <- "search \\\“yyy\\\” where year in [2021] and in [\"xxxxxx\"] return zzz"
Df2 <- "search \\\“yyy\\\” where year in [2020] and in [\"xxxxxx\"] return zzz"
Df3 <- "search \\\“yyy\\\” where year in [2019] and in [\"xxxxxx\"] return zzz"
Df4 <- "search \\\“yyy\\\” where year in [2018] and in [\"xxxxxx\"] return zzz"
Df5 <- "search \\\“yyy\\\” where year in [2017] and in [\"xxxxxx\"] return zzz"
Df1 <- command1(query = Df1, token = token)
Df2 <- command1(query = Df2, token = token)
Df3 <- command1(query = Df3, token = token)
Df4 <- command1(query = Df4, token = token)
Df5 <- command1(query = Df5, token = token)
Final_Df1 <- command2(Df1, dbsource = "APISource", format = "api")
Final_Df2 <- command2(Df2, dbsource = "APISource", format = "api")
Final_Df3 <- command2(Df3, dbsource = "APISource", format = "api")
Final_Df4 <- command2(Df4, dbsource = "APISource", format = "api")
Final_Df5 <- command2(Df5, dbsource = "APISource", format = "api")
Data_Frame <- rbind(Final_Df1, Final_Df2, Final_Df3, Final_Df4, Final_Df5)