Skip to content
Prev 392193 / 398503 Next

Does the function "c" have a character limit?

The limits to the size of vectors, matrices, data frames, lists, or other data structure does not have a simple answer.
1) 2^31 - 1  is the maximum number of rows. https://stackoverflow.com/questions/5233769/practical-limits-of-r-data-frame#:~:text=The%20number%20is%202%5E31,start%20collecting%20several%20of%20them.
2) help(Memory) suggests that the default limit for all variables is 6 Mb. The help page tells you how to change this.
Neither of these two factors have any bearing on this problem except that your vector is not close to these limits.

I got the same result you did when I entered your vector into my system (R 4.2 in RStudio, on 64 bit Windows). I shortened it by removing the first entry and it works.

I can copy the entire line into Microsoft Word, and count the number of characters (including spaces) and I get 4089. There were seven characters in the first entry including the comma and space. If I add seven spaces between MES and the equal sign I get the original outcome. So the limit is on the number of characters in the line. You can get more entries by shortening each entry, or fewer if each entry was longer.

As others have suggested, I would break the line into two pieces and then combine the pieces.

Tim



-----Original Message-----
From: R-help <r-help-bounces at r-project.org> On Behalf Of Rui Barradas
Sent: Wednesday, July 13, 2022 6:36 AM
To: core_contingency <ccontingency at gmail.com>; r-help at r-project.org
Subject: Re: [R] Does the function "c" have a character limit?

[External Email]

Hello,

This is documented behavior.
 From R-intro, last line of section 1.8 [1].


Command lines entered at the console are limited4 to about 4095 bytes (not characters).


The number 4 in limited4 is a footnote link:


some of the consoles will not allow you to enter more, and amongst those which do some will silently discard the excess and some will use it as the start of the next line.



Prof. Ripley called the r-devel mailing list's attention to this in August 2006 when the limit was 1024 [2], it was then increased to the current 4095. I remember seeing a limit of 2048 (?) but couldn't find where.


Try creating a file with your command as only content, then run


x <- readLines("rhelp.txt")
nchar(x)
# [1] 4096


You are above the limit by 1 byte.
Standard solutions are to break the command line, in your case into at least 2 lines, or to source the command from file, like David proposed.


[1]
https://urldefense.proofpoint.com/v2/url?u=https-3A__cran.r-2Dproject.org_doc_manuals_R-2Dintro.html-23R-2Dcommands-5F003b-2Dcase-2Dsensitivity-2Detc&d=DwIDaQ&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRzsn7AkP-g&m=bDsMNmn2OhMbQIvptul8Yl752vW7YkxJ0v91xFMGuYQo9NsNdzAp5k0CD2XzMc9x&s=g5cbrpfyHaIN9sXycd_-f2iDsOcbuzLe2u3KjvQNm-0&e=
[2] https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_pipermail_r-2Ddevel_2006-2DAugust_038985.html&d=DwIDaQ&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRzsn7AkP-g&m=bDsMNmn2OhMbQIvptul8Yl752vW7YkxJ0v91xFMGuYQo9NsNdzAp5k0CD2XzMc9x&s=B1YSca31vHlpy9WJG8o0MBTh7bX4v7M61eWfQ4tmdog&e=


Hope this helps,

Rui Barradas


?s 00:36 de 13/07/2022, core_contingency escreveu:
______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dhelp&d=DwIDaQ&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRzsn7AkP-g&m=bDsMNmn2OhMbQIvptul8Yl752vW7YkxJ0v91xFMGuYQo9NsNdzAp5k0CD2XzMc9x&s=x5SJbPFsoqRiJYh7Y5B0QDKio2Wy4Je38lBBi99AbAE&e=
PLEASE do read the posting guide https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posting-2Dguide.html&d=DwIDaQ&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRzsn7AkP-g&m=bDsMNmn2OhMbQIvptul8Yl752vW7YkxJ0v91xFMGuYQo9NsNdzAp5k0CD2XzMc9x&s=lCG5D1ItMs8G_wkshvm4nBaVq4Ehy_zyq5mnp2zpt2Y&e=
and provide commented, minimal, self-contained, reproducible code.