I have posted the same thing on stackoverflow but no luck with an answer so far and perhaps this is a most appropriate forum for this question.
I have a socket connection between c (client) and R (R acts as a server.. using RStudio). C sends a string of 5 numbers in R. For example:
1 16.29 3.8 0 0
In R I am receiving the string using:
con <- socketConnection(host="localhost", port = 8080, blocking=TRUE, server=TRUE, open="r+")
and the next line is:
helloTall <- readLines(con,1)
The lines are read fine but the problem is that I have to do this very frequently (it is a time step coupling exercise, and so I have to do this >1000 times, and in some cases more than 500k times).
The problem: readLines is extremely slow for this type of work, and readChar is not any better. Is there any other (much) faster way to read the above short string from a connection?
I am using R 3.5.2. readLines takes 1 minute to read these 5 numbers, so with >5000 time steps in my case I would need >5000 minutes!!!
Thank you in advance.