The c() works fine until the vector size is around 4.8KB
When using larger memory size I get "+" and when entering ")" the vector doesn't include all the values.
Is this error? known limitation?
As a workaround, I cut it to several vectors and then combine the vectors c(vec1,vec2,vec3)
Is there a better way?
I see similar behavior where manually entering data with c() truncated the input. Curiously, the vector ended up being 2042 elements when I tried the process in RStudio and it was 2041 elements directly in R. Maybe it is significant that 2^11 = 2048.
What are you doing that requires using c() like that?
When I have had to make a long vector, I either had a file available or the vector followed some pattern that could be made with the rep() or seq() functions. If you must manually enter it, using c() is the only method I know.
To be clear, a vector can occupy a lot of memory. The command
MyVec <- rep(1.3456789, 100000)
makes a 780 KB vector. There appears to be some limitation to the c() function.
The number of bytes in a character isn't always the same. I'm not an expert in this, but here's my mental model:
Characters are stored as a sequence of bytes, and most modern software follows the Unicode Standard to figure out how to translate bytes into characters.
ASCII characters (English alphabet and punctuation, most Greek letters, some accented letters, and some math symbols) are one byte.
In R It isn't a s simple as that ...
I'm using only c(), . and numbers, I test and the memory depend only on the number of characters.
I tried repeated numbers and it didn't really matter.
Apparently the limit used to be lower(1k) and was changed to the 4k we have at present.
Here is the source code for it.
So in theory you could compile your own version of R, with your own choice of line limit...
The size of a character vector in memory is not the sum of the bytes of the individual characters it contains. A character vector is a structure in the background C code and has a bunch of data bundled together: values, length, attributes, etc.
The console commands are just strings of characters, so they don't come with the overhead cost of R objects. If you want to know how many bytes are in a string, use the stringi package:
I had a similar issue pasting long json strings into the console (i.e. ending in "+"). This discussion Does Console impose an upper limit on the length of strings cleared it up for me. Sourcing from a script doesn't have the same limit.