Does Console impose an upper limit on the length of strings

,

Trying to create a string of length 5k in Console results in a next line prompt ("+") wherein another closing " needs to be added even though one was already entered. The resultant string has length 4087.

Is 4087 the maximum length that can be taken as input from Console? Is this documented somewhere? This is well below the default maximum length of string values (i.e., 65535).

foo <- "swY4Dura4GSPHlLTgJgvNDkRmCtMd8J3u6tvCkwpltCX4RtTkxwg0GpftrdgI1YAnF6ykAr3gkNsq9oawBOeh7VYVZnAIYILFa0eT8dY1zxv88SWM3cOfQ6jXZtWqybqZu1xelmRIIudOUkIIzALyE9oen3JFCuvLB4UFkqRDfukVRIo2wuR0fEPN6GmyAzfMiPKCRTpuRDZGxWz82rTqbXwHmL7Z3qOgqbhjXU2rYDqceze80WgNWvOK3nyixWUPebmdX8k27lynityv3eQtFRo9gjegECsvPZRBg3QerwqMZw5etBFYuxR5onCG6ES6QkVW5joqM5yEMgwTIcNyiPFp6UMArmIe5YDsrTnCH1Pw0WJigbOClVZPut4sYRybWblyXefPGRo9k1yZwJLXKwRbquVQrHOVKuxCMTJv9LPu4ftv9vrDd6RsDUYEAcQerZjNDu3PyBCu9gnmThSMQo47odNMTVLi8Zz9jRWHQdTav9lgWTkMOty7878sxLeDRC8RBUjvi8fSgCXnV2pX2J2BeohDIYXTjzn4HzaA5JZUIefcwxdvqylnVbYs94YrAgQ7e0KNpJuCVzvnrzBZvAML2N28Wf2lEvAgH4KDjOoTelyQyJZfT9NA6Fqv6iS4sVs6PGXGVuBxoXZtLbmQ07stvksYCJKu8SP59fFHSBoCOS5sBgqsM0Q4OX6Eu5Vf9yOAi1V0I6oBgjNSzWAJYuipIuRSCvz538kAx0ULIp3zlqti8X1iErwx4ciXmcpUB3zYXfnypUAbWyTwJnUsV22TUDAtIrCJ6Lz9xbhnQem6MfPg44gb4ByQm9jJJXC0YvL4nlX69vFRCuiOqq5uNzJO8nulu8a6b9oHPqaZydk5TTocpCrdgvlATa7hzJOl0TahqVAwaRupvcgVjpEaWbbY51EiuEUruHMYcjyF6tNPigR1Kay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YvJO9zNRBSFSFayJloMqnPaYSOuo3WxXW77nDFMqt20boDFRsRubs0CuPXLJGgBGw8Neyt3PnZIAAGIhkSYZ7jdbJVhgSq55hmiWplTJCavwABYARDG7n8JoDrq2b8JJNyNAI9kzQPe85uJs8guSJoMp5eAgd4lD64bqUDV3MtKoUWvSoteLbvVHC3JvIHcsJmdKJ1BIFE7zECcF5ivDa1ddYyct9E21JhL8QqRTqAsWXlz7BZtVuyCvlrH6IRsPW2if5Q58MeD0cwrV0KaA25O6Adp2VZCURLmkgaw4hMPqB8zkMNGa05yaOc2sE0fLuWvrIOy8MuTzlhtHzuwcJC5mtJkSVrw1HnecQKChRRLu38w2LshK4o6dkMUzle9Tiu3lvIcSaBeby3HIrxtY3NBbpIdLIvauU30PuAp0TKZSztbwHOIsO1OXAbSp94xflpcWHWAyRNDLG0iDKHf9AVcKYD57WupoKS5qUMHw5feaJHFR4hEDUZrSDMOfmIfXE4JlSQn9dG4AfcmeRtWShWg7ffp4No93Jde2NperQGQvd9kRJrPkrdF1jIcWzc2q1IL1BnDRSbehUM9ETRzLXpqKXrhykUBlexqTblsoP9vCYwX1ha0bPoJ69qxq1zbUVdCV3WjRqJXT2YpNYR0alMVgnSpVLE6hRkAxfT1DYhzqraRihq0C2Te1bb5oXAkz8stiBV6S9GYMGB8QUKDScr3MEmP7h8R3IgaoZSrKDuLg1o2R9whTB11V0UKmHuwY7uCjEH1f3fuTXfCrWaOaS77vfF0Tp97857BHNWmQooSfTPKTMC5"

Just to clarify: is the behavior you describe only present in RStudio’s R Console, or do you see the same thing outside of RStudio (e.g. via the R GUI or running R at the command line?)

1 Like

I seem to remember having the same problem and, considering how close your number to multiple of 2 (4096), it looks like it's the same problem.

When I had the same problem I think I've found that this behavior is configurable, but for that you need to recompile R with correct flag set to a bigger number.

1 Like

This is a limit of the console. it is mentioned in R documentation

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

It seems to be hard coded in the source code

You can circumvent this by creating your string in a script then sourcing it or by creating it by pieces and pasting all in last step.

Example of creating programmatically a 5000 length string

test <- paste0(sample(letters, size = 5000, replace = TRUE), collapse = "")
stringr::str_length(test)
#> [1] 5000
4 Likes

Since this sounds like an R problem, not an RStudio IDE problem, I’m moving this post to cut down on noise in the #rstudio-ide category. :broom: :sparkles:

1 Like

Hi. I checked that quickly before. From what I can tell R.app does not show it, at least not in the same way (i.e., it doesn't seem to have this issue). R in Terminal does show it.

From comments below, it seems like a property of console. I don't really get 'the why' of this yet, why that constraint would be built in.

Cool. Thanks. Sorry for putting it in the wrong place initially.

Awesome. Thanks very much.

Would you be able to say why that is hard coded? What would the problem be with entering things greater than the 4096 limit?

Spelunking in the source code, I see that 12 years ago, a previously undocumented and un-centralized console buffer limit was formalized (at 1024 bytes), apparently to deal with a Windows FileReadConsole problem:

Then two years later, the limit was increased:

So for a “why”, I’m going to generically guess good ol’ “performance” :grin:. For more historical detail, I suspect someone would have to ask Brian Ripley.

ETA: Because I love a good research project... there is a bit of kerfuffle around this topic on the r-devel mailing list in April and May 2008 (linking to the end of the somewhat contentious thread): https://stat.ethz.ch/pipermail/r-devel/2008-May/049553.html Doesn’t really answer the question, though.

4 Likes

Thanks! That's helpful.

Pretty weird to me to see the perpetuation of a kludgy and localized fix like that. I could maybe see aligning such a limit to the one imposed on strings, but having one that falls well below that doesn't make sense to me. If anything, it seems like it would be helpful to have an optional setting of that kind for users who are affected.

Cool to see that discussion, although from what I can tell, it doesn't seem centered on this issue, or 'the why' of the issue. Good to see Dirk there. It actually seems like the kind of thing Rolf would engage on, battles around form, whether a reproducible example was provided, etc.

Aha! I found the origin story for CONSOLE_BUFFER_LENGTH:
http://r.789695.n4.nabble.com/Command-line-length-limits-in-R-tp912367.html

(got easier when I remembered about the Nabble mirror to the archives, which is searchable)

Not sure this throws any light on whether other solutions were considered before the limit was raised (or since then). It’s a little tough to search for this topic since there is a lot of interference from discussions of the “vertical” buffer limit and line-wrapping, among other things.

3 Likes