fix

fix(x)
fix allows a function to be edited on the fly. It is a nice tool to make quick changes, perhaps after identifying problems in a function via debug or to insert or remove a call to browser(). (But don’t forget to save the new version elsewhere if it will be needed later.)
  • x – A function to be edited.

Example. A simple function is constructed that squares the a value, adds 5, and then takes the square root. However, there is an error — 4 is added instead of 5 — so the function needs to be edited.
> sqAdd5ThenSqrt <- function(x){
+   x1 <- x^2
+   x2 <- x1+4
+   x3 <- sqrt(x2)
+   return(x3)
+ }
> 
> sqAdd5ThenSqrt(0)
[1] 2
> 
> fix(sqAdd5ThenSqrt)
> # Adjust the 4 to be a 5, save, close
> 
> sqAdd5ThenSqrt(0)
[1] 2.236068
> 

Leave a Reply