Somewhere I read the following question: how would we behave if every time we send an email we would have to pay for each email adress we use? Notice that it was not a question about would be the price, but about the value (perceived or not) of things we do.
On short: if you use Rscript with the argument "-e", pay attention that there is a limit of 10,000 bytes on the total length of expressions used in this way. If your expression is longer, you don't get an error, just a warning, and nothing else. The rest is just details.
You probably know that you can run R expressions from the command line using Rscript:
Rscript -e 'writeLines(text = "fooo", con = "/tmp/delme.txt")' cat /tmp/delme.txt # fooo
Some time ago, I (lost) spent a few hours trying to understand the behavior of some R code which was triggered via Rscript. In many cases it worked ok, but in some cases not, without an obvious error. The context was complicated and it took me some while to break down the problem. When the R expression contained a large list, things did not behave as expected anymore. Here is what happens.
Let's generate some long random text which we then try to write to a file:
A warning is issued, but the message is truncated, I have no idea what the warning is about. The bad thing is not the fact that this does not work as naively expected. I understand that there are technical limitations, but I fail to understand why the command above returns with a success status and not with an error.
An internet search revealed that somebody noticed the problem many years ago. And this is still a problem today. I wonder if the developers involved were fighting (other?) alligators instead of fixing this... With a proactive attitude, I should post the question about why is there no error message in this case in the R mailing list. (In an ideal world I would have the skills to fix this myself.)
The truth is, I gave up lately. For many reasons. Here just a few I encountered recently:
- somebody asks how to do solve a specific problem in R. I asked for a minimal example and I receive a screenshot of an Excel table. My reply: I was actually thinking of a few lines of R code, which I can copy/paste to reproduce the problem. The answer: I don't have any R code, this is what I actually look for... No, I did not further explain that "minimal example" means for me this and this.
- I attend to a short talk presenting results from a survey. On the same slide, two bar charts using two colors: red and blue. I usually associate red with danger. I know, there are cultural differences in the symbolism of colors. I imagine I can understand that. Where I was completely lost: in the first chart, red had indeed negative meaning - a feature got a bad score. But in the second chart (note: on the same slide), red had positive meaning - another feature got a good score. Why on earth would one do this? Being consistent with color across charts is in my mind a basic thing. Obviously only in my bubble...
- I got the question why do I use the bang bang operator with testthat, this makes little sense, because bang bang is just a logical operator. I was totally confused by the question, I asked about the details. Here is the "minimum reproducible example":
x <- 42 testthat::expect_gt(!!x, 43)
!!x # TRUE
#WITHOUT bang bang x <- 42 testthat::expect_gt(x, 43) # Error: `x` is not strictly more than 43. Difference: -1 # with bang bang a clearer error message is generated: x <- 42 testthat::expect_gt(!!x, 43) # Error: 42 is not strictly more than 43. Difference: -1
Here a nice sketch that resonated with me while pondering about these issues: https://sketchplanations.com/context-is-king
Which unfortunately just increases my confusion. In the situations above: was I in the letters context, and the others in the numbers context? Or the other way around? How many contexts are there? What else do I miss? How do I make the jump to another context?
From time to time I watch this.
Maybe all these questions are just alligator fighting...
Make a promise. Show up. Do the work. Repeat.