emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Seeing all the steps when I run an R code block
@ 2022-11-14  3:20 William Denton
  2022-11-15  2:07 ` Ihor Radchenko
  0 siblings, 1 reply; 7+ messages in thread
From: William Denton @ 2022-11-14  3:20 UTC (permalink / raw)
  To: emacs-orgmode

I've got a few problems with R source blocks that I can't figure out.  They 
started late last month, I think.  I'm running Emacs and Org from the 
development trees, refreshing and recompiling regularly.  ESS (the package for 
working with R) is up to date too.

Here's one big problem.  I have a file, /home/wtd/books/reading/test-r.org, and 
in it is this R block:

# -----

#+begin_src R :session R:testing :results value
1
#+end_src

# -----

If I execute that with C-c C-c, the R session buffer starts, but in the wrong 
working directory.  This is in the R session buffer, reported by ESS:

# -----

> setwd('/home/wtd/books')

# -----

It's in the directory *above* where the Org file is!  It should be in 
/home/wtd/books/reading/.

I copied the test file to /tmp/r/test/, and it's fine there.  The session's 
working directory is /tmp/r/test/, not /tmp/r/.

Something strange is going on, but I can't see why.  Is there some way I can 
see all the steps that are happening when I hit C-c C-c on that code block?  Or 
maybe there's some other way to figure it out?  Any suggestions welcome.

Thanks,

Bill

--
William Denton
https://www.miskatonic.org/
Librarian, artist and licensed private investigator.
Toronto, Canada


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Seeing all the steps when I run an R code block
  2022-11-14  3:20 Seeing all the steps when I run an R code block William Denton
@ 2022-11-15  2:07 ` Ihor Radchenko
  2022-11-22 20:58   ` William Denton
  0 siblings, 1 reply; 7+ messages in thread
From: Ihor Radchenko @ 2022-11-15  2:07 UTC (permalink / raw)
  To: William Denton; +Cc: emacs-orgmode

William Denton <wtd@pobox.com> writes:

> I've got a few problems with R source blocks that I can't figure out.  They 
> started late last month, I think.  I'm running Emacs and Org from the 
> development trees, refreshing and recompiling regularly.  ESS (the package for 
> working with R) is up to date too.
>
> Here's one big problem.  I have a file, /home/wtd/books/reading/test-r.org, and 
> in it is this R block:
> ...
> # -----
>
>> setwd('/home/wtd/books')
>
> # -----
>
> It's in the directory *above* where the Org file is!  It should be in 
> /home/wtd/books/reading/.

I tried to test with a clean config and bare ESS installation will raise
the following query:

R:2 starting project directory? /tmp/

Note the default value /tmp which is `default-directory' containing test
Org file in my testing.

You might have set some customization that overrides `default-directory'
setting in ESS.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Seeing all the steps when I run an R code block
  2022-11-15  2:07 ` Ihor Radchenko
@ 2022-11-22 20:58   ` William Denton
  2022-11-23 11:15     ` Ihor Radchenko
  0 siblings, 1 reply; 7+ messages in thread
From: William Denton @ 2022-11-22 20:58 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

On 15 November 2022, Ihor Radchenko wrote:

> I tried to test with a clean config and bare ESS installation will raise
> the following query:
>
> R:2 starting project directory? /tmp/
>
> Note the default value /tmp which is `default-directory' containing test
> Org file in my testing.
>
> You might have set some customization that overrides `default-directory'
> setting in ESS.

You were quite right---thanks for checking.  Recently ESS changed 
ess-startup-directory and now it's aware of projects.  I'd recently put some 
files under Git, which made them a project.  So it was ESS, nor R.

For the record, this will stop that:

(setq ess-startup-directory 'default-directory) ;; "Always start the process in the directory of the current file"

But I have another R problem that does seem to be with Org, coming next ...

Bill

--
William Denton
https://www.miskatonic.org/
Librarian, artist and licensed private investigator.
Toronto, Canada


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Seeing all the steps when I run an R code block
  2022-11-22 20:58   ` William Denton
@ 2022-11-23 11:15     ` Ihor Radchenko
  2022-11-27 11:38       ` Jeremie Juste
  0 siblings, 1 reply; 7+ messages in thread
From: Ihor Radchenko @ 2022-11-23 11:15 UTC (permalink / raw)
  To: William Denton, Jeremie Juste; +Cc: emacs-orgmode

William Denton <wtd@pobox.com> writes:

>> You might have set some customization that overrides `default-directory'
>> setting in ESS.
>
> You were quite right---thanks for checking.  Recently ESS changed 
> ess-startup-directory and now it's aware of projects.  I'd recently put some 
> files under Git, which made them a project.  So it was ESS, nor R.
>
> For the record, this will stop that:
>
> (setq ess-startup-directory 'default-directory) ;; "Always start the process in the directory of the current file"
>
> But I have another R problem that does seem to be with Org, coming next ...

I think this specific issue might be solved on Org side.
We can let-bind `ess-startup-directory' to 'default-directory while
running R source blocks.

CCing the maintainer.

Jeremie, what do you think?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Seeing all the steps when I run an R code block
  2022-11-23 11:15     ` Ihor Radchenko
@ 2022-11-27 11:38       ` Jeremie Juste
  2022-11-27 11:52         ` Ihor Radchenko
  0 siblings, 1 reply; 7+ messages in thread
From: Jeremie Juste @ 2022-11-27 11:38 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: William Denton, emacs-orgmode

Hello William,

Many thanks for reporting.

>
> I think this specific issue might be solved on Org side.
> We can let-bind `ess-startup-directory' to 'default-directory while
> running R source blocks.
>
> CCing the maintainer.
Ihor, many thanks for the suggestion. However I'm not sure it will work
here. The issue is that sometimes ESS has many ways of doing the same
thing so finding a middle ground is more challenging.

A possible configuration related to the point above for ESS is to do the
following

(setq ess-startup-directory nil)

(describe-variable  'ess-startup-directory)


which regardless of the value in the 'default-directory, will start the
R process in the current project directory

With the configuration above org-mode does not have any issues finding
the current directory. For instance

If I move following file test.org in the directory
/home/djj/Documents/projects/R. And run the code chunk I get.

#+begin_src R
  getwd()
#+end_src

#+RESULTS:
: /home/djj/Documents/projects/R


Moving it to /tmp/test/, I get
#+begin_src R
  getwd()
#+end_src

#+RESULTS:
: /tmp/test


Note also that you can force the R process to start in a particular
directory with the dir parameter.

#+begin_src R :dir ~/
  getwd()
#+end_src

#+RESULTS:
: /home/djj


Now on the org-mode side. This is becomes tricky because I don't know
what users expects. For now this issue is delegated to the ESS configuration.
Is the present state a satisfactory one? Please voice out your opinion.

Hope this help, 
Jeremie


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Seeing all the steps when I run an R code block
  2022-11-27 11:38       ` Jeremie Juste
@ 2022-11-27 11:52         ` Ihor Radchenko
  2022-11-27 16:02           ` Jeremie Juste
  0 siblings, 1 reply; 7+ messages in thread
From: Ihor Radchenko @ 2022-11-27 11:52 UTC (permalink / raw)
  To: Jeremie Juste; +Cc: William Denton, emacs-orgmode

Jeremie Juste <jeremiejuste@gmail.com> writes:

> Note also that you can force the R process to start in a particular
> directory with the dir parameter.
>
> #+begin_src R :dir ~/
>   getwd()
> #+end_src
>
> #+RESULTS:
> : /home/djj
>
>
> Now on the org-mode side. This is becomes tricky because I don't know
> what users expects. For now this issue is delegated to the ESS configuration.
> Is the present state a satisfactory one? Please voice out your opinion.

From Org perspective, we should follow what :dir does and fallback to
buffer's `default-directory' otherwise:

16.4 Environment of a Code Block

    The ‘dir’ header argument specifies the default directory during code
    block execution.  If it is absent, then the directory associated with
    the current buffer is used.  In other words, supplying ‘:dir DIRECTORY’
    temporarily has the same effect as changing the current directory with
    ‘M-x cd <RET> DIRECTORY’, and then not setting ‘dir’.  Under the
    surface, ‘dir’ simply sets the value of the Emacs variable
    ‘default-directory’.  Setting ‘mkdirp’ header argument to a non-‘nil’
    value creates the directory, if necessary.
    
       For example, to save the plot file in the ‘Work/’ folder of the home
    directory—notice tilde is expanded:
    
         #+BEGIN_SRC R :file myplot.png :dir ~/Work
           matplot(matrix(rnorm(100), 10), type="l")
         #+END_SRC


So, if R has some way to override the working directory, we should
enforce what we promise in the above section of our manual anyway.

Otherwise, the will lose on Org document reproducibility.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Seeing all the steps when I run an R code block
  2022-11-27 11:52         ` Ihor Radchenko
@ 2022-11-27 16:02           ` Jeremie Juste
  0 siblings, 0 replies; 7+ messages in thread
From: Jeremie Juste @ 2022-11-27 16:02 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: William Denton, emacs-orgmode

Hello Ihor,

On Sunday, 27 Nov 2022 at 11:52, Ihor Radchenko wrote:>

> So, if R has some way to override the working directory, we should
> enforce what we promise in the above section of our manual anyway.
>
> Otherwise, the will lose on Org document reproducibility.

This is a fair point, many thanks the insights.

ESS indeed overrides the working directory when ess-startup-directory is
set to nil. It only happens when :sessions are used though. Here I
created created a git repository in /tmp/test, and when a process is
initiated with session (the last code chunk) the process is started in
at the root of the git repository. 

#+BEGIN_SRC elisp
  (setq ess-startup-directory nil)
#+END_SRC

#+BEGIN_SRC elisp
  default-directory
#+END_SRC

#+RESULTS:
: /tmp/test/books/reading/


#+BEGIN_SRC R
    getwd()
#+END_SRC

#+RESULTS:
: /tmp/test/books/reading


#+begin_src R :session R:testing :results value
getwd()
#+end_src

#+RESULTS:
: /tmp/test

Thanks again, I'll improve this.

Best regards,
Jeremie


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-11-27 16:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-14  3:20 Seeing all the steps when I run an R code block William Denton
2022-11-15  2:07 ` Ihor Radchenko
2022-11-22 20:58   ` William Denton
2022-11-23 11:15     ` Ihor Radchenko
2022-11-27 11:38       ` Jeremie Juste
2022-11-27 11:52         ` Ihor Radchenko
2022-11-27 16:02           ` Jeremie Juste

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).