Re: [ESS] run R code upon starting each ESS session
Thanks a lot Tyler, The 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 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
Re: [ESS] run R code upon starting each ESS session
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
Re: [ESS] run R code upon starting each ESS session
On 3 October 2023 at 18:52, Manuel Teodoro via ESS-help wrote: | Is there a way to run R code upon starting each ESS session? | | Something like Rprofile but I'd like to make it more dependent to emacs. | | What I want is to have a few options settings in my R sessions by default. | Since I use it in different computers but my Emacs configuration is shared | among all of them, I would prefer to keep this also within my emacs config. | | It can be either calling an R script, specifying the path to Rprofile | directly to ESS or passing a string of R code to run at startup. | | Any ideas are appreciated Cool question. My immediate thought (weighted by the fact that I cannot write elisp code ;-) ) was to test for that in the _the standard R startup files_. A quick check of what `Sys.getenv()` returns inside Emacs reveals the `INSIDE_EMACS` env var so now I just added if (interactive() && nzchar(Sys.getenv("INSIDE_EMACS"))) { cat("Hello Emacs user.\n") } to the bottom of .Rprofile and indeed: [... other stuff including the fortunes::fortune call output ...] Hello Emacs user. > setwd('/home/edd/') > but not when I start R on the terminal. That could be start for you. Dirk -- dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org __ ESS-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/ess-help
[ESS] run R code upon starting each ESS session
Is there a way to run R code upon starting each ESS session? Something like Rprofile but I'd like to make it more dependent to emacs. What I want is to have a few options settings in my R sessions by default. Since I use it in different computers but my Emacs configuration is shared among all of them, I would prefer to keep this also within my emacs config. It can be either calling an R script, specifying the path to Rprofile directly to ESS or passing a string of R code to run at startup. Any ideas are appreciated Manuel [[alternative HTML version deleted]] __ ESS-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/ess-help