I m trying to write a function that build an API request. The difficulty: I want to use optinal arguments inside the function, and build the API request according to the presence of these optional arguments. Example:
space <- "earth"
start_date <- "2018-10"
end_date <- "2018-11"
optionalArgument1 <- "America"
optionalArgument2 <- "people"
optionalArgument3 <- "size"
optionalArgument4 <- "ocean"
myfunction <- function(space, start_date, end_date, optionalArgument1, optionalArgument2, optionalArgument3, optionalArgument4){
              api_request <- paste0("https://myapi.com/getData?hello",
                    #NEEDED
                    "&space={s:'", space,"'}",
                    "&period={M:{start:'",start_date,"',end:'",end_date,"'}}",
                    #OPTIONAL
                    "&filter={",
                        "SMALL_filter1:{$sf1:'",optionalArgument1,"'},",
                        "SMALL_filter2:{$sf2:'",optionalArgument2,"'},",
                        "SMALL_filter3:{$sf3:'",optionalArgument3,"'}",
                    "}",
                    "&segment=",optionalArgument4
              )
              return(api_request)    
}
My goal is to allow the function to deliver the api_request, wether a user gives 1, 2, 3 or the 4 optional arguments.
For exemple:
myfunction(space, start_date, end_date, optionalArgument1, optionalArgument4)
Should return something like this:
[1] https://myapi.com/getData?hello&space={s:'earth'}&period={M:{start:'2018-10'end:'2018-11'}}&filter={SMALL_filter1:{$sf1:'America'}}&segment="ocean
An other example:
myfunction(space, start_date, end_date, optionalArgument4)
Should return:
[1] https://myapi.com/getData?hello&space={s:'earth'}&period={M:{start:'2018-10'end:'2018-11'}}&segment="ocean
I am litteraly stuck... Do you have any on how to manage this? Thanks for your help

help("missing").