[R] r function idea: minimize() to turn reproducible_example.R into minimal_reproducible_example.R
Anthony Damico
ajdamico at gmail.com
Thu Sep 10 20:10:18 CEST 2015
just going to throw this idea out there in case it's something that anyone
wants to pursue: if i have an R script and i'm hitting some unexpected
behavior, there should be some way to remove extraneous objects and
manipulations that never touch the line that i'm trying to reproduce.
automatically stepping through the code and removing things that never
affect the final line seems (difficult but) possible. so if my_example.R
looks like this code and i didn't understand why i was hitting an error at
the third line..
x <- mtcars
y <- mean( mtcars$mpg )
mean( x[ , "hello" ] )
..the function i am envisioning would automatically remove the `y <- mean(
mtcars$mpg )` because that object and all subsequent objects do not affect
the error resulting from the third line. in other words, pointing this
minimize() function to the error..
minimize( "my_example.R" , 'Error in `[.data.frame`(x, , "hello") :
undefined columns selected' )
..would find that the error happens on the third line, then follow things
backward and remove any command that does not touch the line that results
in the error. so my reproducible example was three lines, but the minimal
reproducible example became two lines.
i understand it might be impossible to automate all of the minimizing, but
i think there might be enough low-hanging fruit here that this might be a
quick and useful debugging tool for those of us trying to create
easier-to-reproduce code for members of this list.
thanks!
[[alternative HTML version deleted]]
More information about the R-help
mailing list