[R] Substring error

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Jan 25 11:29:05 CET 2007


On Thu, 25 Jan 2007, talepanda wrote:

> It occurs why start or stop could not be converted into integer of
> length > 0 by using as.interger().
>
> More presicely,
> if( !isInteger(sa) || !isInteger(so) || k == 0 || l == 0 ) # c code
> where sa is start, so is stop, k is length(start), l is length(stop)
>
> For example:
>
> substr("orz",character(0),0)
> substr("orz",numeric(0),0)
> substr("orz",logical(0),0)
> substr("orz",integer(0),0)
> substr("orz",NULL,0)
>
> produce the error because of k==0
>
>
> But there seems to be another case which I don't know.

That's essentially it.  The first two conditions are merely protection 
against someone calling the .Internal directly.

In particular, there is no documentation as to what happens if start or 
stop is NA, a case I don't think is handled correctly.

>
>
> On 1/25/07, Shubha Vishwanath Karanth <shubhak at ambaresearch.com> wrote:
>> Hi,
>>
>>
>>
>> Do anybody know when and why the below error we get?
>>
>>
>>
>> Error in substr(x, as.integer(start), as.integer(stop)) :
>>         invalid substring argument(s) in substr()
>>
>>
>>
>> Thanks in advance,
>>
>> Shubha
>>
>>
>> 	[[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch 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 at stat.math.ethz.ch 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.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list