Thanks a lot Tyler, The hook <ess-r-post-run-hook> is exactly what I was looking for. I checked the documentation but I guess I should search better next time.
In case somebody else is interested, I am sending the code directly from within emacs, init file so, no need for extra R scripts. It is a wonderful way to set up R sessions for me. It looks something like this: (defvar my-r-profile "message(\"Welcome from Emacs\")") (defun my-r-ess-init () "Sends variable `tt-r-profile' to an ESS process" (let ((proc (ess-get-process))) (ess-send-string proc tt-r-profile))) (add-hook 'ess-r-post-run-hook 'my-r-ess-init) In this way, whatever you place in <my-r-profile> variable is executed upon startup of the inferior R process. Cheers! Manuel On Tue, Oct 3, 2023 at 9:10 PM Tyler Smith via ESS-help < ess-help@r-project.org> wrote: > On Tue, Oct 3, 2023, at 12:52 PM, Manuel Teodoro via ESS-help wrote: > > Is there a way to run R code upon starting each ESS session? > > > > Hi Manuel, > > ESS provides a hook you can use for this purpose. This is described in the > manual: > > https://ess.r-project.org/Manual/ess.html#Customizing-startup > > To run a custom script each time ESS starts, use something like the > following: > > (add-hook 'ess-r-post-run-hook (lambda () (ess-load-file "foo.R"))) > > - ty > > ______________________________________________ > ESS-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/ess-help > [[alternative HTML version deleted]] ______________________________________________ ESS-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/ess-help