2

I recently came across a question where a new user posted a question and attempted to provide reproducible data, originally posting (in the R language):

lon = c(0, 2.5, 5, 7.5, 10, 12.5, 15, 17.5, 20, 22.5, 25,...,360)
lat = c(17.5, 20, 22.5, 25, 27.5, 30, 32.5, 35, 37.5, 40,...,90)

This was not actually reproducible as anyone responding would have to fill in the ellipsis, or optimize the code using seq(). But the user was a self-described "beginner" to R programming and didn't know.

If I were to answer, I would just make the adjustment in my answer. But I did not know the answer. To ease the work for other (better) coders that may know the answer, I considered editing the OP's code to actually produce the desired data. However, I was unsure if this was appropriate. I ultimately ended up recommending the OP change the code themselves (using seq() - which they did change in the current version).

After searching the meta SO site, I came across several questions and answers that discussed revising and improving code in one's own answer (see Providing answers to code that is different, but more efficient than the OP's code or Is it okay to code-review and improve OP's code when posting an answer? or Should an answer refactor the user code?)

But these are not the same question, nor is my question about code optimization or the efficiency of the approach taken by the author. Specifically: is it ok to make minor edits to fix the code in the OP's question itself so that others in the Stack Exchange community don't have to debug?

2
  • 6
    I wouldn't edit the question, but rather vote to close as "not reproducible". The issue here is that you edit OPs code into something you think still represents OPs described issue, but you may introduce new issue there. It is better to let OP fix their code so they can make sure the code still reproduces the issue they have.
    – Tom
    Commented Dec 30, 2021 at 7:06
  • 1
    (Something seems to be missing near "or approach".) Commented Dec 30, 2021 at 11:35

1 Answer 1

2

Yes

But only when:

  • The correction only fixes some technical details (such as continuing a sequence, fixing a typo in example data, replacing smart quotes with normal quotes, fixing whitespace messed up by copy-pasting in whitespace-sensitive languages, etc).
  • The correction is obvious and no guesswork is involved: any experienced user would come to the same conclusion
  • It is obvious that this error only is present in the question, not the code the OP is running, and is entirely unrelated to the issue the OP is having
  • The question itself is reproducible after the fix

This makes it apply to very few questions, but the example you've provided and the fix seem fine to me.

Closing as non-reproducible because we're misinterpreting something on purpose is not a good thing imo. If someone has written an on-topic, reproducible question, we shouldn't close it on a technicality.

2
  • Great advice, though I come across this issue quite frequently. For instance, just this morning there was a typeo in this question where I chose to comment: "Is df supposed to be df <- data.frame(Y, G, C)? It is currently df <- data.frame(Y, G, T), which puts a constant of TRUE in the third column and does not use C." I also agree with you about not closing on a technicality.
    – jpsmith
    Commented Dec 30, 2021 at 15:26
  • 1
    I'd go Meh there, because it's really irrelevant if C is or isn't in the data frame, referring to global variables in a formula is strange but fine and it's reproducible as-is.
    – Erik A
    Commented Dec 30, 2021 at 15:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .