[R] mapply, quantmod::chart_Series, MoreArgs error with chart_pars(), chart_theme()

Eric Berger er|cjberger @end|ng |rom gm@||@com
Sun Jul 28 18:31:35 CEST 2019


Hi Anul,
Try this (it worked for me)

mapply (chart_Series, mget(symVec), name=infoVec, MoreArgs=list(pars=cp,
theme=ct ))

Best,
Eric


On Sun, Jul 28, 2019 at 7:03 PM Anuj Goyal <anuj.goyal using gmail.com> wrote:

> It compiles without errors, but the chart_pars() and chart_theme() are
> not being applied. eg. the Right Y-axis label still exists in p.pdf.
> Is it possible that cp and ct don't easily vectorize?
>
> # R --silent --vanilla < sof.r
> library(quantmod)
> options("getSymbols.warning4.0"=FALSE)
> options("getSymbols.yahoo.warning"=FALSE)
>
> # setup chart params
> cp <- chart_pars()
> cp$cex=0.55
> cp$mar=c(1,1,0,0) # B,L,T,R
>
> # setup chart theme
> ct <- chart_theme()
> ct$format.labels <- ' ' # AG: space needed to remove bottom x-axis labels
> ct$lylab <- TRUE        # AG: enable left y-axis labels
> ct$rylab <- FALSE       # AG: remove right y-axis labels
> ct$grid.ticks.lwd=1
>
> # read values into vectors
> csv <- read.csv("p.txt", stringsAsFactors = FALSE)
> symVec <- getSymbols(as.vector(csv$s))
> infoVec <- mapply(paste, csv$s, csv$n, sep=": ") # eg. SYM: Name
> cpVec = rep(cp, times=nrow(csv))
>
> # create PDF
> pdf(file = "p.pdf")
> par(mfrow = c( 5, 4 ) )
> mapply (chart_Series, mget(symVec), name=infoVec, MoreArgs=c(cp,ct))
> dev.off()
>
> >>> I tried the options below, but none of them work properly
>
> mapply (chart_Series, mget(symVec), name=infoVec,
> MoreArgs=list("pars=cp","theme=ct"))
> mapply (chart_Series, mget(symVec), name=infoVec, MoreArgs=list("pars=cp"))
> mapply (chart_Series, mget(symVec), name=infoVec,
> MoreArgs=list("theme=ct"))
> mapply (chart_Series, mget(symVec), name=infoVec,
> MoreArgs=list(quote("pars=cp"),quote("theme=ct")))
> mapply (chart_Series, mget(symVec), name=infoVec,
> MoreArgs=list(quote("theme=ct")))
>
> On Sun, Jul 28, 2019 at 7:32 AM Eric Berger <ericjberger using gmail.com> wrote:
> >
> > Hi Anuj,
> > I am providing comments regarding your first attempt to call mapply.
> > Since you are working with named arguments, you shouldn't need to
> include the NULLs in the call.
> > Also you have provided the argument MoreArgs twice, which is what is
> causing the Error message.
> > You can replace that call with the following:
> > mapply (chart_Series, mget(symVec), name=infoVec, MoreArgs=c(cp,ct) )
> >
> > Best,
> > Eric
> >
> >
> > On Sat, Jul 27, 2019 at 8:52 PM Anuj Goyal <anuj.goyal using gmail.com> wrote:
> >>
> >> R version 3.6.0 (2019-04-26) on Mac 10.14.5
> >>
> >> What is the proper way to pass chart_pars() as well as chart_theme()
> >> into MoreArgs for use in quantmod::chart_Series?
> >>
> >> p.txt
> >> =======
> >> s,n
> >> ABBV,AbbVie
> >> BMY,Bristol
> >>
> >> sof.r
> >> =======
> >> # R --silent --vanilla < sof.r
> >> library(quantmod)
> >> options("getSymbols.warning4.0"=FALSE)
> >> options("getSymbols.yahoo.warning"=FALSE)
> >>
> >> # setup chart params
> >> cp <- chart_pars()
> >> cp$cex=0.55
> >> cp$mar=c(1,1,0,0) # B,L,T,R
> >>
> >> # setup chart theme
> >> ct <- chart_theme()
> >> ct$grid.ticks.lwd=1
> >>
> >> # read values into vectors
> >> csv <- read.csv("p.txt", stringsAsFactors = FALSE)
> >> symVec <- getSymbols(as.vector(csv$s))
> >> infoVec <- mapply(paste, csv$s, csv$n, sep=": ") # eg. SYM: Name
> >> cpVec = rep(cp, times=nrow(csv))
> >>
> >> # create PDF
> >> pdf(file = "p.pdf")
> >> par(mfrow = c( 5, 4 ) )
> >> mapply (chart_Series, mget(symVec), name=infoVec, NULL, NULL, NULL,
> >> MoreArgs=cp, MoreArgs=ct)
> >> dev.off()
> >>
> >> Error
> >> ======
> >> Error in mapply(chart_Series, mget(symVec), name = infoVec, NULL,
> >> NULL, : formal argument "MoreArgs" matched by multiple actual
> >> arguments
> >> Execution halted
> >>
> >>
> >> >>> I also tried this.
> >>
> >> mapply (chart_Series, mget(symVec), name=infoVec, NULL, NULL, NULL,
> >> MoreArgs = list(quote('pars=cp')))
> >>
> >> Error in mapply(chart_Series, mget(symVec), name = infoVec, NULL,
> >> NULL, : zero-length inputs cannot be mixed with those of non-zero
> >> length Execution halted
> >>
> >> ______________________________________________
> >> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> 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.
>
>
>
> --
> -Anuj
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list