Almost every tool I use can be exited from terminal by typing exit. But R, being "unique" requires I type q().
Can I set-up something in .Rprofile to achieve this?
On
Yes, you can add to your .Rprofile:
exit <- list()
class(exit) <- 'exiter'
print.exiter <- function(exiterObject){ q() }
which creates an object exit, assigns it the class exiter, and then overrides the print function to actually call q() by only typing exit (which would normally print the object).
Thanks to this blog for the hack.
R has active bindings for this exact purpose:
Now getting
exitfrom the global environment triggers a call toq. Hence any of the following statements will end the R process:But this one will not:
rm(exit)deletes the binding.You'll find more details, including other ways to interact with bindings (locking, accessing, assigning to, etc.), in
?makeActiveBinding.