r - Passing processed ... arguments to plot() via do.call() -


i trying write method extends plot() s3 object list of xy.coords() lists. flexibility use ... need process arguments therein aesthetics (namely xaxt , yaxt arguments). test function wrote below:

#test of ... expansion , modification test = function(x, ...) {   # x list of xy.coords() lists    vargs = list(...)   str(vargs)   #vargs = as.list(substitute(list(...)))[-1l]   # plotting defaults aesthetics if not explicitly set   if (!'xaxt' %in% names(vargs)) vargs[['xaxt']] = 'n'   if (!'yaxt' %in% names(vargs)) vargs[['yaxt']] = 'n'   if (!'pch' %in% names(vargs)) vargs[['pch']] = 16   if (!'cex' %in% names(vargs)) vargs[['cex']] = 0.5   print(vargs)    pargs = c(list(x=x[[1]]$x, y=x[[1]]$y), vargs)   str(pargs)    do.call(plot, pargs) # produces crazy plot bunch of text    plot(x=x[[1]], ...) # produces desired results    invisible(null) } 

the call issue is:

test(y, xaxt='n', yaxt='n', pch=16, cex=0.5) 

where (truncated brevity):

> y[[1]] $x   [1]  0.001111111  0.501388889  1.001388889  1.501388889  2.001388889  2.501388889  3.001388889  3.501388889  4.001388889  $y   [1] 0.132 0.123 0.126 0.143 0.145 0.123 0.128 0.131 0.140 

as i've indicated in comments in test(), expanding ... list of arguments , passing list plot via do.call creates plot text scattered on - so:

strange output do.call(plot, pargs)

otherwise, passing ... directly plot want:

correct/expected plot output

is there i'm doing wrong with,

  • my processing of ...?
  • how i'm passing things do.call()?

am missing step/parameter entirely, or bug in r? session info below , in advance help.

> sessioninfo() r version 3.0.0 (2013-04-03) platform: x86_64-w64-mingw32/x64 (64-bit)  locale: [1] lc_collate=english_united states.1252  lc_ctype=english_united states.1252    lc_monetary=english_united states.1252 [4] lc_numeric=c                           lc_time=english_united states.1252      attached base packages: [1] stats     graphics  grdevices utils     datasets  methods   base       other attached packages: [1] groan_1.0      roxygen2_2.2.2 digest_0.6.3    loaded via namespace (and not attached): [1] brew_1.0-6    stringr_0.6.2 tools_3.0.0  

edit

here more copy+paste compatible version of problem

#test of ... expansion , modification test = function(x, method=c('do.call', 'dots'), ...) {   # x list of xy.coords() lists    vargs = list(...)   str(vargs)   #vargs = as.list(substitute(list(...)))[-1l]   # plotting defaults aesthetics if not explicitly set   if (!'xaxt' %in% names(vargs)) vargs[['xaxt']] = 'n'   if (!'yaxt' %in% names(vargs)) vargs[['yaxt']] = 'n'   if (!'pch' %in% names(vargs)) vargs[['pch']] = 16   if (!'cex' %in% names(vargs)) vargs[['cex']] = 0.5   print(vargs)    pargs = c(list(x=x[[1]]), vargs)   str(pargs)    method = match.arg(method)   switch(method,           do.call={            do.call(plot, pargs) # produces crazy plot bunch of text          }, dots={            plot(x=x[[1]], ...) # produces desired results          })    invisible(null) }  y = list(xy.coords(runif(100), runif(100)))  # produces crazy plot bunch of text test(y, method='do.call', xaxt='n', yaxt='n', pch=16, cex=0.5)  # produces desired results test(y, method='dots', xaxt='n', yaxt='n', pch=16, cex=0.5) 

resolution

the solution @shadow fixed problem. alternative specify ann=false argument in list passed do.call().

the problem axis labels. doing similar

plot(x=c(0.001111111, 0.501388889, 1.001388889, 1.501388889, 2.001388889, 2.501388889, 3.001388889, 3.501388889, 4.001388889, 0.501388889, 1.001388889, 1.501388889, 2.001388889, 2.501388889, 3.001388889, 3.501388889, 4.001388889, 0.501388889, 1.001388889, 1.501388889, 2.001388889, 2.501388889, 3.001388889, 3.501388889, 4.001388889, 0.501388889, 1.001388889, 1.501388889, 2.001388889, 2.501388889, 3.001388889, 3.501388889, 4.001388889, 0.501388889, 1.001388889, 1.501388889, 2.001388889, 2.501388889, 3.001388889, 3.501388889, 4.001388889, 0.501388889, 1.001388889, 1.501388889, 2.001388889, 2.501388889, 3.001388889, 3.501388889, 4.001388889, 0.501388889, 1.001388889, 1.501388889, 2.001388889, 2.501388889, 3.001388889, 3.501388889, 4.001388889))

to fix problem assign labels yourself:

if (!'xlab' %in% names(vargs)) vargs[['xlab']] = names(x[[1]][2]) if (!'ylab' %in% names(vargs)) vargs[['ylab']] = names(x[[1]][1]) 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -