Question

I want to pass arbitrarily long strings to Rscript -e. However, there appears to be a length limit.

Consider the pattern:

$ Rscript -e 'cat("some string goes here")'

If the string has a length of 9993 (on my machine), the command fails and hangs indefinitely. If it has a length of 9992, it outputs the string as I desire. (Your numbers may be different; you can do a binary search to find them if you're so inclined.) The failure looks like this:

WARNING: '-e cat("hihihihihihihihihihihihihihihihihihihihihihihihihihihihihihi!hihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihi

(Note that the string is truncated in exactly this same way in my console: this input string is not the full input string. This also means that I know there's a WARNING, but I don't know what it's warning me about!)

What is a good way to get around this limitation? I could stick the content in a temp file under /tmp, but that strikes me as too messy.

What I'm really looking to do is to use Rscript (specifically, knitr) as a text filter: old string goes in, new string comes out.

For reference, here is my first iteration of this filter. The problem is that when the input becomes too large, nanoc hangs indefinitely. (I now know this is because Rscript is hanging; hence, this question.)

Was it helpful?

Solution

This is a limitation of readline (or whatever function is doing duty for stdin), not Rscript or R. If you don't want to follow Joshua's advice to source from a file then you will need to rewrite your system's input program.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top