Re: [R] cbind for list of zoo objects
Thanks for the explanations. Wouldn't the following bit of checking in do.call() make it easier to figure such things out in the future? my.call - function(what,args,...) { ## Get the name of the function to call. if (!is.character(what)) whatStr - deparse(substitute(what)) else whatStr - what callFctn - paste0(gsub(paste0('.',class(args[[1]])),'',whatStr), '.', class(args[[1]])) ## Check whether list names are arguments to the function. if ( any( names(args) %in% names(formals(callFctn)) ) ) warning( 'Element of args is also an argument for ', callFctn, '.' ) ## Do the actual call. do.call( what, args, ... ) } Sent from my iPhone On Apr 8, 2013, at 7:23 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Mon, Apr 8, 2013 at 3:54 PM, Harry Mamaysky h.mamay...@gmail.com wrote: Can someone explain why this happens when one of the list elements is named 'all'? zz - list( zoo(1:10,1:10), zoo(101:110,1:10), zoo(201:210,1:10) ) names(zz)-c('test','bar','foo') do.call(cbind,zz) test bar foo 1 1 101 201 2 2 102 202 3 3 103 203 4 4 104 204 5 5 105 205 6 6 106 206 7 7 107 207 8 8 108 208 9 9 109 209 10 10 110 210 names(zz)-c('test','all','foo') do.call(cbind,zz) test foo 1 1 201 2 2 202 3 3 203 4 4 204 5 5 205 6 6 206 7 7 207 8 8 208 9 9 209 10 10 210 all= is an argument to cbind.zoo so it cannot be used as a column name. args(zoo:::cbind.zoo) function (..., all = TRUE, fill = NA, suffixes = NULL, drop = FALSE) NULL -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] cbind for list of zoo objects
On Tue, Apr 9, 2013 at 7:31 AM, Harry Mamaysky h.mamay...@gmail.com wrote: Thanks for the explanations. Wouldn't the following bit of checking in do.call() make it easier to figure such things out in the future? Sure, it would have helped you figure out your issue, but you don't want a *warning* when you purposefully try to set named function arguments. I.e., what if you want to set a function argument to something other than its default value? Do you really want a warning when you do that? my.call - function(what,args,...) { ## Get the name of the function to call. if (!is.character(what)) whatStr - deparse(substitute(what)) else whatStr - what callFctn - paste0(gsub(paste0('.',class(args[[1]])),'',whatStr), '.', class(args[[1]])) ## Check whether list names are arguments to the function. if ( any( names(args) %in% names(formals(callFctn)) ) ) warning( 'Element of args is also an argument for ', callFctn, '.' ) ## Do the actual call. do.call( what, args, ... ) } Sent from my iPhone On Apr 8, 2013, at 7:23 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Mon, Apr 8, 2013 at 3:54 PM, Harry Mamaysky h.mamay...@gmail.com wrote: Can someone explain why this happens when one of the list elements is named 'all'? zz - list( zoo(1:10,1:10), zoo(101:110,1:10), zoo(201:210,1:10) ) names(zz)-c('test','bar','foo') do.call(cbind,zz) test bar foo 1 1 101 201 2 2 102 202 3 3 103 203 4 4 104 204 5 5 105 205 6 6 106 206 7 7 107 207 8 8 108 208 9 9 109 209 10 10 110 210 names(zz)-c('test','all','foo') do.call(cbind,zz) test foo 1 1 201 2 2 202 3 3 203 4 4 204 5 5 205 6 6 206 7 7 207 8 8 208 9 9 209 10 10 210 all= is an argument to cbind.zoo so it cannot be used as a column name. args(zoo:::cbind.zoo) function (..., all = TRUE, fill = NA, suffixes = NULL, drop = FALSE) NULL -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com -- Joshua Ulrich | about.me/joshuaulrich FOSS Trading | www.fosstrading.com R/Finance 2013: Applied Finance with R | www.RinFinance.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] cbind for list of zoo objects
That's true. So perhaps there should be a flag that turns on this error checking. Often args is just a list that gets generated automatically and you don't know what all of its elements are. It just leads to a bit of non-deterministic behavior. It would be useful to have the option of flagging when one of those list elements (inadvertently) has the same name as an argument of what. Sent from my iPhone On Apr 9, 2013, at 9:07 AM, Joshua Ulrich josh.m.ulr...@gmail.com wrote: On Tue, Apr 9, 2013 at 7:31 AM, Harry Mamaysky h.mamay...@gmail.com wrote: Thanks for the explanations. Wouldn't the following bit of checking in do.call() make it easier to figure such things out in the future? Sure, it would have helped you figure out your issue, but you don't want a *warning* when you purposefully try to set named function arguments. I.e., what if you want to set a function argument to something other than its default value? Do you really want a warning when you do that? my.call - function(what,args,...) { ## Get the name of the function to call. if (!is.character(what)) whatStr - deparse(substitute(what)) else whatStr - what callFctn - paste0(gsub(paste0('.',class(args[[1]])),'',whatStr), '.', class(args[[1]])) ## Check whether list names are arguments to the function. if ( any( names(args) %in% names(formals(callFctn)) ) ) warning( 'Element of args is also an argument for ', callFctn, '.' ) ## Do the actual call. do.call( what, args, ... ) } Sent from my iPhone On Apr 8, 2013, at 7:23 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Mon, Apr 8, 2013 at 3:54 PM, Harry Mamaysky h.mamay...@gmail.com wrote: Can someone explain why this happens when one of the list elements is named 'all'? zz - list( zoo(1:10,1:10), zoo(101:110,1:10), zoo(201:210,1:10) ) names(zz)-c('test','bar','foo') do.call(cbind,zz) test bar foo 1 1 101 201 2 2 102 202 3 3 103 203 4 4 104 204 5 5 105 205 6 6 106 206 7 7 107 207 8 8 108 208 9 9 109 209 10 10 110 210 names(zz)-c('test','all','foo') do.call(cbind,zz) test foo 1 1 201 2 2 202 3 3 203 4 4 204 5 5 205 6 6 206 7 7 207 8 8 208 9 9 209 10 10 210 all= is an argument to cbind.zoo so it cannot be used as a column name. args(zoo:::cbind.zoo) function (..., all = TRUE, fill = NA, suffixes = NULL, drop = FALSE) NULL -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com -- Joshua Ulrich | about.me/joshuaulrich FOSS Trading | www.fosstrading.com R/Finance 2013: Applied Finance with R | www.RinFinance.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] cbind for list of zoo objects
On Tue, Apr 9, 2013 at 9:15 AM, Harry Mamaysky h.mamay...@gmail.com wrote: That's true. So perhaps there should be a flag that turns on this error checking. Often args is just a list that gets generated automatically and you don't know what all of its elements are. It just leads to a bit of non-deterministic behavior. It would be useful to have the option of flagging when one of those list elements (inadvertently) has the same name as an argument of what. You can force an error by specifying all the default arguments. Using the version of zz with an all component it will encounter all= twice: do.call(cbind, c(zz, all = TRUE, fill = NA, suffixes = list(NULL), drop = FALSE)) Error in cbind(deparse.level, ...) : formal argument all matched by multiple actual arguments or more compactly: do.call(cbind, c(zz, formals(zoo:::cbind.zoo)[-1])) Error in cbind(deparse.level, ...) : formal argument all matched by multiple actual arguments -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] cbind for list of zoo objects
That's a nice solution. Thanks. Sent from my iPhone On Apr 9, 2013, at 10:00 AM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Tue, Apr 9, 2013 at 9:15 AM, Harry Mamaysky h.mamay...@gmail.com wrote: That's true. So perhaps there should be a flag that turns on this error checking. Often args is just a list that gets generated automatically and you don't know what all of its elements are. It just leads to a bit of non-deterministic behavior. It would be useful to have the option of flagging when one of those list elements (inadvertently) has the same name as an argument of what. You can force an error by specifying all the default arguments. Using the version of zz with an all component it will encounter all= twice: do.call(cbind, c(zz, all = TRUE, fill = NA, suffixes = list(NULL), drop = FALSE)) Error in cbind(deparse.level, ...) : formal argument all matched by multiple actual arguments or more compactly: do.call(cbind, c(zz, formals(zoo:::cbind.zoo)[-1])) Error in cbind(deparse.level, ...) : formal argument all matched by multiple actual arguments -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] cbind for list of zoo objects
Because 'all' is the name of one of the arguments to cbind.zoo: R args(cbind.zoo) function (..., all = TRUE, fill = NA, suffixes = NULL, drop = FALSE) NULL do.call constructs a call somewhat like: R cbind(test=zz$test, all=zz$all, foo=zz$foo) The same thing would happen for list elements named 'fill', 'suffixes', or 'drop'. Best, -- Joshua Ulrich | about.me/joshuaulrich FOSS Trading | www.fosstrading.com R/Finance 2013: Applied Finance with R | www.RinFinance.com On Mon, Apr 8, 2013 at 2:54 PM, Harry Mamaysky h.mamay...@gmail.com wrote: Can someone explain why this happens when one of the list elements is named 'all'? zz - list( zoo(1:10,1:10), zoo(101:110,1:10), zoo(201:210,1:10) ) names(zz)-c('test','bar','foo') do.call(cbind,zz) test bar foo 1 1 101 201 2 2 102 202 3 3 103 203 4 4 104 204 5 5 105 205 6 6 106 206 7 7 107 207 8 8 108 208 9 9 109 209 10 10 110 210 names(zz)-c('test','all','foo') do.call(cbind,zz) test foo 1 1 201 2 2 202 3 3 203 4 4 204 5 5 205 6 6 206 7 7 207 8 8 208 9 9 209 10 10 210 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] cbind for list of zoo objects
On Mon, Apr 8, 2013 at 3:54 PM, Harry Mamaysky h.mamay...@gmail.com wrote: Can someone explain why this happens when one of the list elements is named 'all'? zz - list( zoo(1:10,1:10), zoo(101:110,1:10), zoo(201:210,1:10) ) names(zz)-c('test','bar','foo') do.call(cbind,zz) test bar foo 1 1 101 201 2 2 102 202 3 3 103 203 4 4 104 204 5 5 105 205 6 6 106 206 7 7 107 207 8 8 108 208 9 9 109 209 10 10 110 210 names(zz)-c('test','all','foo') do.call(cbind,zz) test foo 1 1 201 2 2 202 3 3 203 4 4 204 5 5 205 6 6 206 7 7 207 8 8 208 9 9 209 10 10 210 all= is an argument to cbind.zoo so it cannot be used as a column name. args(zoo:::cbind.zoo) function (..., all = TRUE, fill = NA, suffixes = NULL, drop = FALSE) NULL -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.