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
R has active bindings for this exact purpose:
makeActiveBinding("exit", function() q(), .GlobalEnv)
Now getting exit from the global environment triggers a call to q. Hence any of the following statements will end the R process:
exit
get("exit")
exit + 1
typeof(exit)
(function() exit)()
But this one will not:
(function(exit) exit)(0)
rm(exit) deletes the binding.
You'll find more details, including other ways to interact with bindings (locking, accessing, assigning to, etc.), in ?makeActiveBinding.
Yes, you can add to your
.Rprofile:which creates an object
exit, assigns it the classexiter, and then overrides theprintfunction to actually callq()by only typingexit(which would normally print the object).Thanks to this blog for the hack.