Re: [Rd] capture "->"

2024-03-03 Thread Dmitri Popavenko
On Sat, Mar 2, 2024 at 7:58 PM Gabor Grothendieck wrote: > Would it be good enough to pass it as a formula? Using your definition of > foo > > foo(~ A -> result) > ## result <- ~A > > foo(~ result <- A) > ## ~result <- A > Yes, to pass as a formula would be the idea. It's just that the

Re: [Rd] capture "->"

2024-03-02 Thread Gabor Grothendieck
Would it be good enough to pass it as a formula? Using your definition of foo foo(~ A -> result) ## result <- ~A foo(~ result <- A) ## ~result <- A On Fri, Mar 1, 2024 at 4:18 AM Dmitri Popavenko wrote: > > Hi everyone, > > I am aware this is a parser issue, but is there any

Re: [Rd] capture "->"

2024-03-02 Thread avi.e.gross
ions or have the ability to do conversions. But those ideas belong in a more mainstream R mailing list. -Original Message- From: Duncan Murdoch Sent: Saturday, March 2, 2024 6:32 AM To: Adrian Dușa ; avi.e.gr...@gmail.com Cc: r-devel Subject: Re: [Rd] capture "->"

Re: [Rd] capture "->"

2024-03-02 Thread Dmitri Popavenko
On Sat, Mar 2, 2024 at 1:31 PM Duncan Murdoch wrote: > You can't change the parser. Changes like `+` <- `-` change the > function that is called when the expression contains a function call to > `+`; this happens in `eval()`, not in `parse()`. There are never any > function calls to `->`,

Re: [Rd] capture "->"

2024-03-02 Thread Duncan Murdoch
You can't change the parser. Changes like `+` <- `-` change the function that is called when the expression contains a function call to `+`; this happens in `eval()`, not in `parse()`. There are never any function calls to `->`, because the parser outputs a call to `<-` with the operands

Re: [Rd] capture "->"

2024-03-02 Thread Adrian Dușa
That would have been an elegant solution, but it doesn't seem to work: > `->` <- `+` > 1 -> 3 # expecting 4 Error in 3 <- 1 : invalid (do_set) left-hand side to assignment It is possible to reassign other multiple character operators: > `%%` <- `+` > 1 %% 3 [1] 4 The assignment operator `->` is

Re: [Rd] capture "->"

2024-03-01 Thread avi.e.gross
o: avi.e.gr...@gmail.com Cc: r-devel ; Dmitri Popavenko Subject: Re: [Rd] capture "->" I would also be interested in that. For me, this is interesting for my QCA package, over which Dmitri and I have exchanged a couple of messages. The "<-" operator is used to denote n

Re: [Rd] capture "->"

2024-03-01 Thread Adrian Dușa
;<<-" too? > > I do wonder if you can re-declare the assignment operators or would that > mess up the parser. > > -Original Message- > From: R-devel On Behalf Of Duncan Murdoch > Sent: Friday, March 1, 2024 9:23 AM > To: Dmitri Popavenko > Cc

Re: [Rd] capture "->"

2024-03-01 Thread avi.e.gross
it also support the global assignment of "->>" as compared to ""<<-" too? I do wonder if you can re-declare the assignment operators or would that mess up the parser. -Original Message- From: R-devel On Behalf Of Duncan Murdoch Sent: Friday, March 1, 2

Re: [Rd] capture "->"

2024-03-01 Thread Duncan Murdoch
On 01/03/2024 8:51 a.m., Dmitri Popavenko wrote: On Fri, Mar 1, 2024 at 1:00 PM Duncan Murdoch > wrote: ... I was thinking more of you doing something like   parse(text = "A -> B", keep.source = TRUE) I forget what the exact rules are for

Re: [Rd] capture "->"

2024-03-01 Thread Dmitri Popavenko
On Fri, Mar 1, 2024 at 1:00 PM Duncan Murdoch wrote: > ... > I was thinking more of you doing something like > > parse(text = "A -> B", keep.source = TRUE) > > I forget what the exact rules are for attaching srcrefs to arguments of > functions, but I do remember they are a little strange,

Re: [Rd] capture "->"

2024-03-01 Thread Duncan Murdoch
On 01/03/2024 5:25 a.m., Dmitri Popavenko wrote: Dear Duncan, On Fri, Mar 1, 2024 at 11:30 AM Duncan Murdoch > wrote: ... If you parse it with srcrefs, you could look at the source.  The parser doesn't record whether it was A -> B or B <- A

Re: [Rd] capture "->"

2024-03-01 Thread Dmitri Popavenko
Dear Duncan, On Fri, Mar 1, 2024 at 11:30 AM Duncan Murdoch wrote: > ... > If you parse it with srcrefs, you could look at the source. The parser > doesn't record whether it was A -> B or B <- A anywhere else. > Thank you, this gets me closer but it still needs a little push: > foo <-

Re: [Rd] capture "->"

2024-03-01 Thread Duncan Murdoch
On 01/03/2024 4:17 a.m., Dmitri Popavenko wrote: Hi everyone, I am aware this is a parser issue, but is there any possibility to capture the use of the inverse assignment operator into a formula? Something like: foo <- function(x) substitute(x) gives: foo(A -> B) B <- A I wonder if

[Rd] capture "->"

2024-03-01 Thread Dmitri Popavenko
Hi everyone, I am aware this is a parser issue, but is there any possibility to capture the use of the inverse assignment operator into a formula? Something like: > foo <- function(x) substitute(x) gives: > foo(A -> B) B <- A I wonder if there is any possibility whatsoever to signal the use

Re: [Rd] capture error messages from loading shared objects

2023-11-28 Thread Adrian Dușa
Thanks Henrik and Bill, Indeed, but I do have a function called tryCatchWEM() in package admisc that captures all that. My use case was to test for different architectures (for instance, arm64 vs Intel MacOS) embedding R in cross-platform applications. I needed to test if the package could be

Re: [Rd] capture error messages from loading shared objects

2023-11-28 Thread Henrik Bengtsson
Careful; tryCatch() on non-error conditions will break out of what's evaluated, e.g. res <- tryCatch({ cat("1\n") message("2") cat("3\n") 42 }, message = identity) will output '1' but not '3', because it returns as soon as the first message() is called. To "record" messages (same for

Re: [Rd] capture error messages from loading shared objects

2023-11-28 Thread Bill Dunlap
If you would like to save the error message instead of suppressing it, you can use tryCatch(message=function(e)e, ...). -BIll On Tue, Nov 28, 2023 at 3:55 AM Adrian Dusa wrote: > Once again, Ivan, many thanks. > Yes, that does solve it. > Best wishes, > Adrian > > On Tue, Nov 28, 2023 at 11:28 

Re: [Rd] capture error messages from loading shared objects

2023-11-28 Thread Adrian Dusa
Once again, Ivan, many thanks. Yes, that does solve it. Best wishes, Adrian On Tue, Nov 28, 2023 at 11:28 AM Ivan Krylov wrote: > В Tue, 28 Nov 2023 10:46:45 +0100 > Adrian Dusa пишет: > > > tryCatch(requireNamespace("foobar"), error = function(e) e) > > I think you meant loadNamespace()

Re: [Rd] capture error messages from loading shared objects

2023-11-28 Thread Ivan Krylov
В Tue, 28 Nov 2023 10:46:45 +0100 Adrian Dusa пишет: > tryCatch(requireNamespace("foobar"), error = function(e) e) I think you meant loadNamespace() (which throws errors), not requireNamespace() (which internally uses tryCatch(loadNamespace(...)) and may or may not print the error depending on

[Rd] capture error messages from loading shared objects

2023-11-28 Thread Adrian Dusa
Fellow R developers, I can capture usual error message using the normal way: > tc <- tryCatch(1 + a, error = function(e) e) > tc However I have troubles capturing the error message from this type of error: > tc <- tryCatch(requireNamespace("foobar"), error = function(e) e) Loading required

Re: [Rd] Capture output of install.packages (pipe system2)

2013-09-24 Thread Jeroen Ooms
On Mon, Sep 23, 2013 at 6:50 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: x - system2(Rscript, -e \install.packages('MASS', repos='http://probability.ca/cran')\, stdout=TRUE, stderr=TRUE) Thank you, this suggestion seems to work (although I agree that starting 3 procs to install a single

Re: [Rd] Capture output of install.packages (pipe system2)

2013-09-24 Thread Hadley Wickham
You shouldn't assume - use file.path(R.home(bin), R) Hadley On Tue, Sep 24, 2013 at 9:37 AM, Jeroen Ooms jeroen.o...@stat.ucla.edu wrote: On Mon, Sep 23, 2013 at 6:50 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: x - system2(Rscript, -e \install.packages('MASS',

Re: [Rd] Capture output of install.packages (pipe system2)

2013-09-24 Thread Jeroen Ooms
On Mon, Sep 23, 2013 at 6:34 PM, Simon Urbanek simon.urba...@r-project.org wrote: On top of my head for full capture I can only think of custom C code that will re-direct stderr/out FDs as desired (it's really trivial to re-direct to files, for dynamic capture it's a little more involved but

Re: [Rd] Capture output of install.packages (pipe system2)

2013-09-24 Thread Duncan Murdoch
On 13-09-24 10:37 AM, Jeroen Ooms wrote: On Mon, Sep 23, 2013 at 6:50 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: x - system2(Rscript, -e \install.packages('MASS', repos='http://probability.ca/cran')\, stdout=TRUE, stderr=TRUE) Thank you, this suggestion seems to work (although I agree

[Rd] Capture output of install.packages (pipe system2)

2013-09-23 Thread Jeroen Ooms
Is there any way to capture output (both stdout and stderr) from install.packages? Solutions like sink and capture.output don't work because the install.packages calls out to system2 which is executed in a separate process: test - capture.output(install.packages(MASS)) The system2 function

Re: [Rd] Capture output of install.packages (pipe system2)

2013-09-23 Thread Duncan Murdoch
On 13-09-23 2:17 PM, Jeroen Ooms wrote: Is there any way to capture output (both stdout and stderr) from install.packages? Solutions like sink and capture.output don't work because the install.packages calls out to system2 which is executed in a separate process: test -

Re: [Rd] Capture output of install.packages (pipe system2)

2013-09-23 Thread Simon Urbanek
Duncan, On Sep 23, 2013, at 10:20 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 13-09-23 2:17 PM, Jeroen Ooms wrote: Is there any way to capture output (both stdout and stderr) from install.packages? Solutions like sink and capture.output don't work because the install.packages calls

Re: [Rd] Capture output of install.packages (pipe system2)

2013-09-23 Thread Duncan Murdoch
On 13-09-23 6:34 PM, Simon Urbanek wrote: Duncan, On Sep 23, 2013, at 10:20 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 13-09-23 2:17 PM, Jeroen Ooms wrote: Is there any way to capture output (both stdout and stderr) from install.packages? Solutions like sink and capture.output

Re: [Rd] Capture output of install.packages (pipe system2)

2013-09-23 Thread Hadley Wickham
Brian Ripley's reply describes how it is done in the tools package. For example, as I sent privately to Jeroen, x - system2(Rscript, -e \install.packages('MASS', repos='http://probability.ca/cran')\, stdout=TRUE, stderr=TRUE) captures all of the output from installing MASS. As Jeroen

Re: [Rd] Capture output of install.packages (pipe system2)

2013-09-23 Thread Paul Gilbert
On 13-09-23 08:20 PM, Hadley Wickham wrote: Brian Ripley's reply describes how it is done in the tools package. For example, as I sent privately to Jeroen, x - system2(Rscript, -e \install.packages('MASS', repos='http://probability.ca/cran')\, stdout=TRUE, stderr=TRUE) captures all of the