Trento-R-User-Group / RUTrentoOpenData

Query dati.trentino directly from R!
GNU General Public License v3.0
1 stars 0 forks source link

Explore '...' usage #1

Open Giackgamba opened 7 years ago

Giackgamba commented 7 years ago

Arguments inheritability: I want to add parameters on trentino(q) such as _rows, pack_sel, ressel. Can I use ...? How?

Arguments that are not used by the called function, but may be used by the subsequent selecting functions

bubbobne commented 7 years ago

Maybe we can use ellipsis as a list:

other_func(...){
   optional_param<- as.list(substitute(list(...)))
    optional_param["rows"]

}

trentino <- function(q,...) {
    /// search query
    other_func(...)
 }

but It seems to me too verbose

Giackgamba commented 7 years ago

What I wanted to have is the ability to add optional parameters to the main function and pass them to the downloader function. Some datasets saved as csv has a ';' separator, while others has ',', user should be able to specify it, if it's not detected by default,

bubbobne commented 7 years ago

ok, We can use ellipsis in this way:


test <-function(x,...){
if( hasArg(separator)){
//read data with defined separator
}

}
test("query", separator=";")
bubbobne commented 7 years ago

I have add optional parameters when read shape file, and I got in trouble with ellipsis. I think it's better to pass the ellipsis to the download_resource function, and extract the optional value before use it, for example:

download_resource <- function(res, ...) {
    format <- res$resource$format
    url <- URLencode(res$resource$url)
   [..............]
  if (format == "shp"){
        #path is my optional parameter
        if (hasArg(path)) {
            downloads_folder <- list(...)$path
            print(downloads_folder)
        }else{
            downloads_folder <- NULL
        }
        dat <- getSpatialDataFrame(url,downloads_folder)
    }