No Clocks

No Clocks

4334 bookmarks
Newest
8 Conditions | Advanced R
8 Conditions | Advanced R
8.1 Introduction The condition system provides a paired set of tools that allow the author of a function to indicate that something unusual is happening, and the user of that function to deal with...
·adv-r.hadley.nz·
8 Conditions | Advanced R
Pi Coding Agent
Pi Coding Agent
A terminal-based coding agent
·pi.dev·
Pi Coding Agent
8.4 Handling conditions | Advanced R
8.4 Handling conditions | Advanced R
The book is designed primarily for R users who want to improve their programming skills and understanding of the language. It should also be useful for programmers coming to R from other languages, as help you to understand why R works the way it does.
So far we’ve just signalled conditions, and not looked at the objects that are created behind the scenes. The easiest way to see a condition object is to catch one from a signalled condition. That’s the job of rlang::catch_cnd()
But before we can learn about and use these handlers, we need to talk a little bit about condition objects. These are created implicitly whenever you signal a condition, but become explicit inside the handler.
Built-in conditions are lists with two elements: message, a length-1 character vector containing the text to display to a user. To extract the message, use conditionMessage(cnd). call, the call which triggered the condition. As described above, we don’t use the call, so it will often be NULL. To extract it, use conditionCall(cnd).
Conditions also have a class attribute, which makes them S3 objects.
The protected code is evaluated in the environment of tryCatch(), but the handler code is not, because the handlers are functions. This is important to remember if you’re trying to modify objects in the parent environment.
The handler functions are called with a single argument, the condition object. I call this argument cnd, by convention. This value is only moderately useful for the base conditions because they contain relatively little data. It’s more useful when you make your own custom conditions, as you’ll see shortly.
tryCatch() has one other argument: finally. It specifies a block of code (not a function) to run regardless of whether the initial expression succeeds or fails. This can be useful for clean up, like deleting files, or closing connections. This is functionally equivalent to using on.exit() (and indeed that’s how it’s implemented) but it can wrap smaller chunks of code than an entire function.
The handlers set up by tryCatch() are called exiting handlers, because they cause code to exit once the condition has been caught. By contrast, withCallingHandlers() sets up calling handlers: code execution continues normally once the handler returns. This tends to make withCallingHandlers() a more natural pairing with the non-error conditions. Exiting and calling handlers use “handler” in slighty different senses:
One important side-effect unique to calling handlers is the ability to muffle the signal. By default, a condition will continue to propagate to parent handlers, all the way up to the default handler (or an exiting handler, if provided):
If you want to prevent the condition “bubbling up” but still run the rest of the code in the block, you need to explicitly muffle it with rlang::cnd_muffle():
·bookdown.dongzhuoer.com·
8.4 Handling conditions | Advanced R
Please Shut Up! Verbosity Control in Packages
Please Shut Up! Verbosity Control in Packages
We recently introduced a new paragraph to the development version of our dev guide Provide a way for users to opt out of verbosity, preferably at the package level: make message creation dependent on an environment variable or option (like “usethis.quiet” in the usethis package), rather than on a function parameter. The control of messages could be on several levels (“none, “inform”, “debug”) rather than logical (no messages at all / all messages). Control of verbosity is useful for end users but also in tests. More interesting comments can be found in an issue of the tidyverse design guide.
·ropensci.org·
Please Shut Up! Verbosity Control in Packages
Semantic Compression
Semantic Compression
An introduction to the idea that code should be approached with a mindset towards compressing it semantically, rather than orienting it around objects.
·caseymuratori.com·
Semantic Compression
An Inclusive, Unifying API for Progress Updates
An Inclusive, Unifying API for Progress Updates
A minimal, unifying API for scripts and packages to report progress updates from anywhere including when using parallel processing. The package is designed such that the developer can to focus on what progress should be reported on without having to worry about how to present it. The end user has full control of how, where, and when to render these progress updates, e.g. in the terminal using utils::txtProgressBar(), cli::cli_progress_bar(), in a graphical user interface using utils::winProgressBar(), tcltk::tkProgressBar() or shiny::withProgress(), via the speakers using beepr::beep(), or on a file system via the size of a file. Anyone can add additional, customized, progression handlers. The progressr package uses Rs condition framework for signaling progress updated. Because of this, progress can be reported from almost anywhere in R, e.g. from classical for and while loops, from map-reduce API:s like the lapply() family of functions, purrr, plyr, and foreach. It will also work with parallel processing via the future framework, e.g. lapply(...) |> futurize() and purrr::map(...) |> futurize()', which uses future.apply::future_lapply() and furrr::future_map() internally. The package is compatible with Shiny applications.
·progressr.futureverse.org·
An Inclusive, Unifying API for Progress Updates
PowerShell Logging v2 – Easily create log files
PowerShell Logging v2 – Easily create log files
Sometime back in 2011 when I first started using PowerShell, I developed some standard functions to handle the creating and management of log files for my PowerShell scripts. These functions were s…
·9to5it.com·
PowerShell Logging v2 – Easily create log files
Gdal cli from c
Gdal cli from c
The C API for gdal CLI algorithms is available in gdalalgorithm.h.
Added in version 3.12
The first step is to get the instance of the GDALGlobalAlgorithmRegistry with GDALGetGlobalAlgorithmRegistry() and then call GDALAlgorithmRegistryInstantiateAlgFromPath() with the path of the algorithm.
Once done with a GDALAlgorithmRegistryH handle, the memory associated to it can be released with GDALAlgorithmRegistryRelease() (the algorithm handles got from the registry will still be valid).
Execution of the algorithm is performed by GDALAlgorithmRun(), with an optional progress function. Proper closing of the output dataset must be performed with GDALAlgorithmFinalize(). Once done with the algorithm handle, it must be released with GDALAlgorithmFinalize().
When outputting to a MEM -- In Memory datasets dataset, you typically want to get the output dataset with:
·gdal.org·
Gdal cli from c
A memory model for production async R: mirai 2.7.0 and mori 0.2.0
A memory model for production async R: mirai 2.7.0 and mori 0.2.0
Two CRAN releases extend R's foundations for production async: bounded queues and `try_mirai()` in mirai 2.7.0, plus mori 0.2.0 graduating from experimental status.
·opensource.posit.co·
A memory model for production async R: mirai 2.7.0 and mori 0.2.0
Building a Computer in R
Building a Computer in R
One Time When R Wasn't a Language for Statistical Computing and Graphics
·landeranalytics.com·
Building a Computer in R
niri
niri
·niri-wm.github.io·
niri
The Tools I Use — Nick Janetakis
The Tools I Use — Nick Janetakis
Here's a list of software and hardware that I use on a regular basis as a developer and video creator. I will be keeping it updated.
·nickjanetakis.com·
The Tools I Use — Nick Janetakis