In many instances, I have seen code that is poorly formatted or all in one line (like below using R). Is it appropriate to edit the code so that it is more legible? I know in some instances these are necessary edits that would improve the post (according to here and here).
However, recently, someone nicely pointed out that I was doing too many small/minor edits on questions (as I usually fix issues when I see them), but I did not realize I was bumping some questions up in the active queue. So, I am trying to make sure my edits are "necessary".
One example that I recently saw was where someone provided their data (a dataframe in R), but it was all in one line, such as:
df <- structure(list(Site = structure(c(1L, 1L, 1L), .Label = "Agriculture", class = "factor"), CowId = 1000:1002, Result = list(c("A", "B"), "C", "C")), class = c("grouped_df", "tbl_df", "tbl", "data.frame"), row.names = c(NA, -3L), groups = structure(list( Site = structure(c(1L, 1L, 1L), .Label = "FarmA", class = "factor"), CowId = 1000:1002, .rows = structure(list(1L, 2L, 3L), ptype = integer(0), class = c("vctrs_list_of", "vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame" ), row.names = c(NA, -3L), .drop = TRUE))
So, in this case, is it worth formatting the code so that the data structure is more visible? Something like this:
df <-
structure(
list(
Site = structure(c(1L, 1L, 1L), .Label = "Agriculture", class = "factor"),
CowId = 1000:1002,
Result = list(c("A", "B"), "C", "C")
),
class = c("grouped_df", "tbl_df", "tbl", "data.frame"),
row.names = c(NA,-3L),
groups = structure(
list(
Site = structure(c(1L, 1L, 1L), .Label = "FarmA", class = "factor"),
CowId = 1000:1002,
.rows = structure(
list(1L, 2L, 3L),
ptype = integer(0),
class = c("vctrs_list_of", "vctrs_vctr", "list")
)
),
class = c("tbl_df", "tbl", "data.frame"),
row.names = c(NA,-3L),
.drop = TRUE
)
)
I am just wondering where the balance is for improving posts but not causing frustration to people when things get bumped up in the active queue.
This could be a duplicate question, but was not able to find an immediate answer.
"true"
where they're expectingtrue
, etc.). However, if the language is whitespace-aware, like Python, my code edits only consist of adding code fences where necessary and deleting excessive numbers of blank lines. Anything else may cause issues.dput
, which isn't meant to be read so much as copied over to a script in order to make reproducible data. This is one case where domain knowledge matters—no matter how you format it, we don't ask for dputs in order to read them, we ask for them precisely because you can copy them overconst query = 'SELECT yadda, yadda2 FROM some vast list of stuff;'
it's hard to reformat the question without teaching the user how to use multiline strings in whatever language. So I just repeat the query, formatted line by, in the answer, and suggest the user look up multiline strings.