unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
* guix shell readline issue with R
@ 2023-07-02 17:57 Kyle Andrews
  2023-07-02 19:09 ` Edouard Klein
  2023-08-23 14:56 ` Simon Tournier
  0 siblings, 2 replies; 8+ messages in thread
From: Kyle Andrews @ 2023-07-02 17:57 UTC (permalink / raw)
  To: help-guix


Dear Guix,

When I run `guix install r` and then start an R process I get a readline-enabled REPL where I can abort commands with C-c C-c while keeping the process alive afterwards. When I run R from `guix shell r -- R` I don't get any readline support in R. Pressing C-c immediately aborts the process. This is inconvenient for interactive exploration. Is there a way to make guix shell work the same way as if the R command was installed into a profile?

Thanks for your help,
Kyle


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

* Re: guix shell readline issue with R
  2023-07-02 17:57 guix shell readline issue with R Kyle Andrews
@ 2023-07-02 19:09 ` Edouard Klein
  2023-07-02 20:53   ` Kyle Andrews
  2023-07-02 22:14   ` Kyle Andrews
  2023-08-23 14:56 ` Simon Tournier
  1 sibling, 2 replies; 8+ messages in thread
From: Edouard Klein @ 2023-07-02 19:09 UTC (permalink / raw)
  To: Kyle Andrews; +Cc: help-guix

Hi Kyle,


Running
guix shell r

and then
R

will get you the C-c handling you want.

There is indeed readline support with guix shell r -- R:
up arrow to get history, c-E, c-A for end of line, start if line, etc.

I think maybe the problem lies not with readline but with the way
signals are handled. I can't seem to understand exactly how, but I would
look into that direction.

Cheers,

Edouard.

Kyle Andrews <kyle@posteo.net> writes:

> Dear Guix,
>
> When I run `guix install r` and then start an R process I get a readline-enabled
> REPL where I can abort commands with C-c C-c while keeping the process alive
> afterwards. When I run R from `guix shell r -- R` I don't get any readline
> support in R. Pressing C-c immediately aborts the process. This is inconvenient
> for interactive exploration. Is there a way to make guix shell work the same way
> as if the R command was installed into a profile?
>
> Thanks for your help,
> Kyle


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

* Re: guix shell readline issue with R
  2023-07-02 19:09 ` Edouard Klein
@ 2023-07-02 20:53   ` Kyle Andrews
  2023-07-02 22:14   ` Kyle Andrews
  1 sibling, 0 replies; 8+ messages in thread
From: Kyle Andrews @ 2023-07-02 20:53 UTC (permalink / raw)
  To: Edouard Klein; +Cc: help-guix


Edouard Klein <edou@rdklein.fr> writes:

> Hi Kyle,
>
>
> Running
> guix shell r
>
> and then
> R
>
> will get you the C-c handling you want.
>
> There is indeed readline support with guix shell r -- R:
> up arrow to get history, c-E, c-A for end of line, start if line, etc.
>
> I think maybe the problem lies not with readline but with the way
> signals are handled. I can't seem to understand exactly how, but I would
> look into that direction.
>
> Cheers,
>
> Edouard.

Thanks Edouard for pointing out that the problem is signals-related and not readline related.

I spent a little time refreshing my memory about signals, looking at the following shell scripting references.

=> https://linuxcommand.org/lc3_wss0150.php
=> https://mywiki.wooledge.org/SignalTrap

I tried using tools like trap, wait, and exec, but haven't yet found an approach that worked.

I placed a basic R manifest here if anyone would like to try:

=> https://paste.debian.net/1284782/

Basically my shell script was:

```
#!/bin/sh
guix shell -m /tmp/manifest.scm -- R --no-save --quiet --no-restore
```

In the R REPL I interactively test the problem with:

```
while(TRUE) Sys.sleep(1)
  C-c C-c
```

Cheers,
Kyle

> Kyle Andrews <kyle@posteo.net> writes:
>
>> Dear Guix,
>>
>> When I run `guix install r` and then start an R process I get a readline-enabled
>> REPL where I can abort commands with C-c C-c while keeping the process alive
>> afterwards. When I run R from `guix shell r -- R` I don't get any readline
>> support in R. Pressing C-c immediately aborts the process. This is inconvenient
>> for interactive exploration. Is there a way to make guix shell work the same way
>> as if the R command was installed into a profile?
>>
>> Thanks for your help,
>> Kyle



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

* Re: guix shell readline issue with R
  2023-07-02 19:09 ` Edouard Klein
  2023-07-02 20:53   ` Kyle Andrews
@ 2023-07-02 22:14   ` Kyle Andrews
  2023-07-03  7:58     ` Edouard Klein
  1 sibling, 1 reply; 8+ messages in thread
From: Kyle Andrews @ 2023-07-02 22:14 UTC (permalink / raw)
  To: Edouard Klein; +Cc: help-guix


Edouard Klein <edou@rdklein.fr> writes:

> Hi Kyle,
>
>
> Running
> guix shell r
>
> and then
> R
>
> will get you the C-c handling you want.

Hi Edouard,

I wrote another reply, but forgot to comment on this because I feel like I am missing something here.

It would be really convenient if I could just write a shell script like that. For me the first command hijacks the execution so that the script cannot invoke R. Is there a workaround avoiding -- which would let me automate that with a script?

Cheers,
Kyle


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

* Re: guix shell readline issue with R
  2023-07-02 22:14   ` Kyle Andrews
@ 2023-07-03  7:58     ` Edouard Klein
  2023-07-03 21:55       ` Kyle Andrews
  0 siblings, 1 reply; 8+ messages in thread
From: Edouard Klein @ 2023-07-03  7:58 UTC (permalink / raw)
  To: Kyle Andrews; +Cc: help-guix

Hy Kyle,


Here is a script that restores the ctrl-C behaviour of R, whithin a guix
shell.

I must admit I don't exactly understand the finer points of why it
works, but just trapping SIGINT in the script is enough for R to behave.

My intuition is SIGINT is sent to the whole group. The script interrupts
R. If we trap it in the script, it does nothing. R gets it as well and
acts on it like you expect.

Let me know if the problem still persists.

Here is the script:

#!/usr/bin/env -S guix shell r -- bash
set -m
R&
function ctrlc(){
    # Doing nothing
    true
}
trap ctrlc SIGINT
fg

Cheers,

Edouard.


Kyle Andrews <kyle@posteo.net> writes:

> Edouard Klein <edou@rdklein.fr> writes:
>
>> Hi Kyle,
>>
>>
>> Running
>> guix shell r
>>
>> and then
>> R
>>
>> will get you the C-c handling you want.
>
> Hi Edouard,
>
> I wrote another reply, but forgot to comment on this because I feel like I am missing something here.
>
> It would be really convenient if I could just write a shell script like that.
> For me the first command hijacks the execution so that the script cannot invoke
> R. Is there a workaround avoiding -- which would let me automate that with a
> script?
>
> Cheers,
> Kyle


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

* Re: guix shell readline issue with R
  2023-07-03  7:58     ` Edouard Klein
@ 2023-07-03 21:55       ` Kyle Andrews
  2023-07-04 12:27         ` Edouard Klein
  0 siblings, 1 reply; 8+ messages in thread
From: Kyle Andrews @ 2023-07-03 21:55 UTC (permalink / raw)
  To: Edouard Klein; +Cc: help-guix


Edouard Klein <edou@rdklein.fr> writes:

> Here is a script that restores the ctrl-C behaviour of R, whithin a guix shell.
>
> I must admit I don't exactly understand the finer points of why it works, but just trapping SIGINT in the script is enough for R to behave.
>
> My intuition is SIGINT is sent to the whole group. The script
> interrupts R. If we trap it in the script, it does nothing. R gets it as well and acts on it like you expect.

Thanks, Edouard!

Your script worked perfectly just as you described. I was sorely missing that `set -m' call and passing true from the bash function. I also really like your idea for the shebang line.

Best Regards,
Kyle



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

* Re: guix shell readline issue with R
  2023-07-03 21:55       ` Kyle Andrews
@ 2023-07-04 12:27         ` Edouard Klein
  0 siblings, 0 replies; 8+ messages in thread
From: Edouard Klein @ 2023-07-04 12:27 UTC (permalink / raw)
  To: Kyle Andrews; +Cc: help-guix

Credit where credit is due, the shebang's idea comes from guix's manual.

You can also do the following:

#+begin_src bash
#!/usr/bin/env bash
# Autowrap self in guix shell
if [ -z "${GUIX_ENVIRONMENT:-}" ]
then
    guix shell YOUR DEPENDENCIES HERE -- "$0" "$@"
    exit 0
fi
ACTUAL CONTENTS OF THE SCRIPT HERE
#+end_src

Cheers !

Edouard

Kyle Andrews <kyle@posteo.net> writes:

> Edouard Klein <edou@rdklein.fr> writes:
>
>> Here is a script that restores the ctrl-C behaviour of R, whithin a guix shell.
>>
>> I must admit I don't exactly understand the finer points of why it works, but just trapping SIGINT in the script is enough for R to behave.
>>
>> My intuition is SIGINT is sent to the whole group. The script
>> interrupts R. If we trap it in the script, it does nothing. R gets it as well and acts on it like you expect.
>
> Thanks, Edouard!
>
> Your script worked perfectly just as you described. I was sorely missing that `set -m' call and passing true from the bash function. I also really like your idea for the shebang line.
>
> Best Regards,
> Kyle


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

* Re: guix shell readline issue with R
  2023-07-02 17:57 guix shell readline issue with R Kyle Andrews
  2023-07-02 19:09 ` Edouard Klein
@ 2023-08-23 14:56 ` Simon Tournier
  1 sibling, 0 replies; 8+ messages in thread
From: Simon Tournier @ 2023-08-23 14:56 UTC (permalink / raw)
  To: Kyle Andrews, help-guix; +Cc: Ricardo Wurmus

Hi,

On Sun, 02 Jul 2023 at 17:57, Kyle Andrews <kyle@posteo.net> wrote:

> When I run `guix install r` and then start an R process I get a
> readline-enabled REPL where I can abort commands with C-c C-c while
> keeping the process alive afterwards. When I run R from `guix shell r
> -- R` I don't get any readline support in R. Pressing C-c immediately
> aborts the process. This is inconvenient for interactive
> exploration. Is there a way to make guix shell work the same way as if
> the R command was installed into a profile? 

Ah indeed.  And note that it just works with the option --container.
Hum, I do not know what is twisted here.

Ricardo, any idea?


Cheers,
simon


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

end of thread, other threads:[~2023-08-23 16:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-02 17:57 guix shell readline issue with R Kyle Andrews
2023-07-02 19:09 ` Edouard Klein
2023-07-02 20:53   ` Kyle Andrews
2023-07-02 22:14   ` Kyle Andrews
2023-07-03  7:58     ` Edouard Klein
2023-07-03 21:55       ` Kyle Andrews
2023-07-04 12:27         ` Edouard Klein
2023-08-23 14:56 ` Simon Tournier

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).