[R] String buffer

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue May 20 20:34:30 CEST 2008


On Tue, 20 May 2008, Duncan Murdoch wrote:

> On 5/20/2008 12:58 PM, Applejus wrote:
>> Hello,
>> 
>> I have an expression "a" in R that has about 2300 characters and I want to
>> convert it to a string using toString or as.character. The problem is I am
>> only getting the first 500 or so characters when I convert it to string. I
>> tried to use substring in order to convert one bunch at a time, but when I
>> type substring(a, 498, 1000) I get only 2 characters, meaning it seems 
>> there
>> is a limit of 500 characters at most, even for the substring function.
>
> When you deparse a long expression, it comes back as a multi-element 
> character vector.  as.character() only returns the first element.  You can 
> get all of them by calling deparse() directly, and then perhaps you'll want 
> to paste them together.
>
> I'm not sure if this is a bug in as.character, or just an undocumented 
> limitation.

It is documented, on the help page!

      'as.character' truncates components of language objects to 500
      characters (was about 70 before 1.3.1).

>> The weird part is that the conversion with as.character works fine with
>> Splus, but not in R.
>
> I wouldn't call it "weird"; there are lots of differences between the two 
> programs.  They have been developed independently.
>
> Duncan Murdoch
>
>> 
>> Could anyone help me out? Is there a string buffer function like that of
>> java? Should I change something in the console configuration? (I tried to
>> increase the buffer but it still doesn't work) 
>> Thanks!
>
> ______________________________________________
> R-help at 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.
>

-- 
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