From m4rbel at gmail.com  Thu Aug 27 00:13:42 2015
From: m4rbel at gmail.com (Martin Bel)
Date: Wed, 26 Aug 2015 19:13:42 -0300
Subject: [Rd] sprintf error: "only 100 arguments allowed"
In-Reply-To: <55DDF6B6.9090303@fredhutch.org>
References: <CALEtyTH5HKBsyVdrt7mCDCfAC5vBmOtShX8C7dVjGQs6LsKQ0Q@mail.gmail.com>
	<55DC30A4.9060504@stats.ox.ac.uk> <55DDF6B6.9090303@fredhutch.org>
Message-ID: <CALEtyTF3HvoxdSdti3FWwj1YzLbGS-Z34DpG4sPjoP5gVhVGfA@mail.gmail.com>

Thanks for the help Herv?, sprintf2 does the job! Brillant!
I see Brian, thanks. I imagined it was there for a reason, but had to
check. I guess you don't pass more than 100 arguments to sprintf every day.
;)
Best.
Mart?n



2015-08-26 14:26 GMT-03:00 Herv? Pag?s <hpages at fredhutch.org>:

> Wouldn't it make sense to have this in the man page?
>
> The 8192-byte limitation for 'fmt' is mentioned but not this one.
>
> Thanks,
> H.
>
>
> On 08/25/2015 02:08 AM, Prof Brian Ripley wrote:
>
>>  From the sources:
>>
>> #define MAXNARGS 100
>> /*               ^^^ not entirely arbitrary, but strongly linked to
>> allowing %$1 to %$99 !*/
>>
>>
>>
>> On 22/08/2015 04:21, Martin Bel wrote:
>>
>>> I'm trying to apply a function defined in the VW R docs, that attemps to
>>> convert a data.table object to Vowpal Wabbit format. In the process i'm
>>> getting the error in printf mentioned in the subject.
>>> The original function is here:
>>> https://github.com/JohnLangford/vowpal_wabbit/blob/master/R/dt2vw.R
>>>
>>>
>>> Below there is a small example that reproduces the error. The function
>>> works great with smaller (less than 100 columns), as shown.
>>>
>>> Any suggestions of alternative methods to acomplish the same would be
>>> great, but I'm basically asking, is there a reason for the 100 arguments
>>> limitation?
>>>
>>>
>>> # Source this function#
>>> https://github.com/JohnLangford/vowpal_wabbit/blob/master/R/dt2vw.R
>>> # Here is a gist
>>> source('
>>> https://gist.githubusercontent.com/martinbel/a013c2bd2333b85eeb76/raw/7b68ede0385f3d8684a07854e8d6ca527b9cd441/dt2vw.R
>>> ')
>>>
>>>
>>> library(data.table)
>>>
>>> X = cbind(matrix(rnorm(1:1010), nrow=10, ncol=101), sample(c(1, -1),
>>> 10, T))
>>> X = as.data.table(X)
>>> X[, weight:=ifelse(V102 == 1, 3, 1)]
>>> # check out function arguments
>>> head(dt2vw, 2)# function (data, fileName, namespaces = NULL, target,
>>> weight = NULL, #                 tag = NULL, hard_parse = F)
>>>
>>> namespaces = list(a = list(varName = sprintf('V%s',1:50), keepSpace=F),
>>>                    b = list(varName = sprintf('V%s',51:101),
>>> keepSpace=F))
>>>
>>> dt2vw(data=X, fileName='../out.vw', namespaces = NULL,
>>>        target='V102', weight = 'weight',
>>>        tag = NULL, hard_parse = F)
>>> ### error
>>> # [1] "sprintf('%f %f |A V1:%f V2:%f V3:%f V4:%f V5:%f V6:%f V7:%f
>>> V8:%f V9:%f V10:%f V11:%f V12:%f V13:%f V14:%f V15:%f V16:%f V17:%f
>>> V18:%f V19:%f V20:%f V21:%f V22:%f V23:%f V24:%f V25:%f V26:%f V27:%f
>>> V28:%f V29:%f V30:%f V31:%f V32:%f V33:%f V34:%f V35:%f V36:%f V37:%f
>>> V38:%f V39:%f V40:%f V41:%f V42:%f V43:%f V44:%f V45:%f V46:%f V47:%f
>>> V48:%f V49:%f V50:%f V51:%f V52:%f V53:%f V54:%f V55:%f V56:%f V57:%f
>>> V58:%f V59:%f V60:%f V61:%f V62:%f V63:%f V64:%f V65:%f V66:%f V67:%f
>>> V68:%f V69:%f V70:%f V71:%f V72:%f V73:%f V74:%f V75:%f V76:%f V77:%f
>>> V78:%f V79:%f V80:%f V81:%f V82:%f V83:%f V84:%f V85:%f V86:%f V87:%f
>>> V88:%f V89:%f V90:%f V91:%f V92:%f V93:%f V94:%f V95:%f V96:%f V97:%f
>>> V98:%f V99:%f V100:%f V101:%f ',V102, weight, V1, V2, V3, V4, V5, V6,
>>> V7, V8, V9, V10, V11, V12, V13, V14, V15, V16, V17, V18, V19, V20,
>>> V21, V22, V23, V24, V25, V26, V27, V28, V29, V30, V31, V32, V33, V34,
>>> V35, V36, V37, V38, V39, V40, V41, V42, V43, V44, V45, V46, V47, V48,
>>> V49, V50, V51, V52, V53, V54, V55, V56, V57, V58, V59, V60, V61, V62,
>>> V63, V64, V65, V66, V67, V68, V69, V70, V71, V72, V73, V74, V75, V76,
>>> V77, V78, V79, V80, V81, V82, V83, V84, V85, V86, V87, V88, V89, V90,
>>> V91, V92, V93, V94, V95, V96, V97, V98, V99, V100, V101)"
>>> # Error in sprintf("%f %f |A V1:%f V2:%f V3:%f V4:%f V5:%f V6:%f V7:%f
>>> V8:%f V9:%f V10:%f V11:%f V12:%f V13:%f V14:%f V15:%f V16:%f V17:%f
>>> V18:%f V19:%f V20:%f V21:%f V22:%f V23:%f V24:%f V25:%f V26:%f V27:%f
>>> V28:%f V29:%f V30:%f V31:%f V32:%f V33:%f V34:%f V35:%f V36:%f V37:%f
>>> V38:%f V39:%f V40:%f V41:%f V42:%f V43:%f V44:%f V45:%f V46:%f V47:%f
>>> V48:%f V49:%f V50:%f V51:%f V52:%f V53:%f V54:%f V55:%f V56:%f V57:%f
>>> V58:%f V59:%f V60:%f V61:%f V62:%f V63:%f V64:%f V65:%f V66:%f V67:%f
>>> V68:%f V69:%f V70:%f V71:%f V72:%f V73:%f V74:%f V75:%f V76:%f V77:%f
>>> V78:%f V79:%f V80:%f V81:%f V82:%f V83:%f V84:%f V85:%f V86:%f V87:%f
>>> V88:%f V89:%f V90:%f V91:%f V92:%f V93:%f V94:%f V95:%f V96:%f V97:%f
>>> V98:%f V99:%f V100:%f V101:%f ",  : # only 100 arguments are allowed
>>> # works
>>> dt2vw(data=X[, 50:dim(X)[2], with=FALSE],
>>>        fileName='../out.vw', namespaces = NULL,
>>>        target='V102', weight = 'weight',
>>>        tag = NULL, hard_parse = F)
>>>
>>> system('head -3 ../out.vw')
>>>
>>>     [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> R-devel at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>>
>>
>>
> --
> Herv? Pag?s
>
> Program in Computational Biology
> Division of Public Health Sciences
> Fred Hutchinson Cancer Research Center
> 1100 Fairview Ave. N, M1-B514
> P.O. Box 19024
> Seattle, WA 98109-1024
>
> E-mail: hpages at fredhutch.org
> Phone:  (206) 667-5791
> Fax:    (206) 667-1319
>

	[[alternative HTML version deleted]]



[Rd] sprintf error: "only 100 arguments allowed"
Martin Bel