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