alamak
catches your errors and lets a Pixel Pal (patent pending) tell you all about it.
The name comes from the Singlish/Malay expression "alamak!", which is an exclamation that follows a surprising/unsettling event, or a minor nuisance, according to the vibe.
As usual, install throught devtools
:
devtools::install_github("gdagstn/alamak")
You may think that in order to use alamak
you need to know how to code. The opposite is true: not knowing how to code will let alamak
shine in all its glory.
Wrap your call into a call to alamak()
. If a warning or an error occurs, a Pixel Pal (patent pending) appears on the screen and tells you what they think about you and your situation.
library(alamak)
alamak(your_function(), pixelpal = "Jerry")
Alternatively, and if you are using R 4.0 and above, you can use the |>
(pipe) operator (or the %>%
magrittr
pipe for versions below). Note that sometimes the function call on the left has to be enclosed in parentheses to work:
sum(a, 3) |> alamak(pixpal = "Lenny")
sum(a, 3) %>% alamak(pixpal = "Oniji")
# This also works but needs parentheses
(a + 3) |> alamak(pixpal = "Buster")
alamak()
displays compressed Pixel Pals by default. Compression saves space, but in some terminals it does not work well. You can disable it by adding
compress = FALSE
to the alamak()
arguments.
The Rstudio console default theme (TextMate) has a line height that doesn't render "pixels" properly. To fix this you can edit the .rstheme file by adding this element:
#rstudio_console_output {
line-height: 1.2 !important;
}
alamak
is quite dumb and should not be used in professional settings, unless that's your thing.
There are 5 Pixel Pals (patent pending) available:
Jerry, a parrot who doesn't like you very much:
Buster, a cool lemon:
Lenny, a supportive velociraptor who is also great with kids:
Oniji, an 18th century Japanese kabuki actor who only speaks in haiku:
E10N, a no-nonsense robot from the not so distant future
You can create another Pixel Pal (patent pending) yourself! If you have a 16x16 (can be bigger but may distort the text on the screen) PNG file with transparency you can load it. As a reference, consider that every "pixel" is actually two whitespaces with a colored background, so a 32x32 picture will take up 64 spaces in size in the terminal.
You only need to make a list with the following elements:
crayon
: the result of a call tomakePixelPal()
where the argument is the path to a PNG filemessages
: a nested list containing two other lists:Error
: a character vector of error messagesWarning
: a character vector of warning messages
You can choose whether you want the Pixel Pal to be compressed or not.
new_pixelpal = list("crayon" = makePixPal("path/to/picture.png", compress = TRUE),
"messages" = list(
"Error" = c("The first possible message",
"The second possible message",
"And so on",
"You know the drill"),
"Warning" = c("A warning message",
"Another warning message")
)
)
then use it with alamak
alamak(your_function(), new_pixelpal)
- Gábor Csárdi for the
crayon
package - Simon Urbanek for the
png
package - Trevor L. Davis for suggestions on compression using Unicode Blocks