I did something silly in an R session. I wrote
print = FALSE
Now I can't print things!
print [1] FALSE
How do I get it back?
rm
will not remove base objects, so you can just run:
rm(print)
Interestingly, you can print things:
> print <- FALSE
> print
[1] FALSE
> print("hi")
[1] "hi"
> rm(print)
> print("hi")
[1] "hi"
> print
function (x, ...)
UseMethod("print")
<bytecode: 0x2a3a148>
<environment: namespace:base>
The irony here is that you did NOT overwrite it. You created a data object named "print" and when you typed print
at the console, the eval-print loop took over and returned it. Had you tested for the behavior of print correctly by typing print("something")
or print(42)
you would have seen that the interpreter was still able to find the print.default
function in the base NAMESPACE. Defining data objects with the same names as existing functions is bad practice, not because they overwrite in the R interpreter, but because they overwrite in minds of users. The interpreter determines your intent (well, it determines what it will do anyway) by seeing whether there is a open-parenthesis which signifies a function call. If the letters p-r-i-n-t are followed by "(" then the interpreter looks at the class of the argument and dispatches the appropriate print method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With