[R] readChar maxing out at screen width when using gnu screen?

Thomas Nyberg tomnyberg at gmail.com
Sat Oct 25 00:37:56 CEST 2014


I am running:

R version 3.1.1 (2014-07-10) -- "Sock it to Me"
Platform: x86_64-unknown-linux-gnu (64-bit)

It is an Amazon 64 Linux instance with the following version: 
3.3.4-5.fc17.x86_64

I compiled R myself as well as the newest version of gnu screen.


I create a file with a couple hundred bytes by doing the following 
(using bash):

 > for i in {1..100}; do echo $i >> testfile; done

Next I load R and run the following:

 > readChar('testfile', 200)
[1] 
"1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n2"

That output is exactly the width of the screen (as in the window in gnu 
screen). If I double the screen width (which I can do by removing my 
split screen mode), it will return the following string:

[1] 
"1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n"


Now my normal belief here would be that screen is somehow causing the 
bug, but honestly that makes no sense at all. What global changes could 
screen possibly make which would cause readChar to ignore its parameter 
telling it how many numbers to read in? I mean writing this in C would 
be a few lines and touch nothing that screen could affect.

Can somebody reproduce this? If not, another solution to my issue would 
be if somebody could tell me another way to read in an entire file as a 
string. The following is what I'm using which is causing the problem:

readfile <- function(filepath) {
     text <- readChar(filepath, file.info(filepath)$size)
     text
}

Thanks for any help. Cheers.

Thomas



More information about the R-help mailing list