I am increasingly editing SO posts. I guess you all know those cases when the OP tries to produce a MCVE and dput
s their large sample data frames into the question - taking many many lines of code, although they could be formatted to one line. Removing the white space would usually do the job and increase the readability of the post, without damaging its reproducibility.
But, I have now often enough stupidly deleted this manually and just have no clue how to do this better. I don't see how to get the whole block evaluated as a string, in order to use "conventional" 'replace whitespace in string', because the block contains many quotation marks which would need escaping.
An example (with a comparatively small data frame):
structure(list(a = 1:5, b = structure(1:5, .Label = c("a", "b",
"c", "d", "e"), class = "factor")), class = "data.frame", row.names = c(NA,
-5L))
should be reduced to :
structure(list(a=1:5,b=structure(1:5,.Label=c("a","b","c","d","e"),class="factor")),class="data.frame",row.names=c(NA,-5L))