Skip to content

Instantly share code, notes, and snippets.

@jonocarroll
Created March 9, 2017 12:02
Show Gist options
  • Save jonocarroll/a5f8b302f8c310346ad1a8b590781378 to your computer and use it in GitHub Desktop.
Save jonocarroll/a5f8b302f8c310346ad1a8b590781378 to your computer and use it in GitHub Desktop.
get outta here, warnings
if ("stringi" %in% utils::installed.packages()) {
flip <- stringi::stri_unescape_unicode('(\\u256f\\u00b0\\u25a1\\u00b0\\uff09\\u256f\\ufe35 \\u253b\\u2501\\u253b')
warnings <- function(...) base::warnings(flip)
}
@jimhester
Copy link

You don't need stringi, just use the escapes directly

warnings <- function(...) base::warnings("\u256f\u00b0\u25a1\u00b0\uff09\u256f\ufe35 \u253b\u2501\u253b")

@jimhester
Copy link

Also best practices to test if an optional package is available is

if (requireNamespace("stringi", quietly = TRUE)) { }

See the note section of ?installed.packages for reasons why.

Note:

This can be slow when thousands of packages are installed, so do
not use this to find out if a named package is installed (use
‘system.file’ or ‘find.package’) nor to find out if a package is
usable (call ‘require’ and check the return value) nor to find
details of a small number of packages (use ‘packageDescription’).
It needs to read several files per installed package, which will
be slow on Windows and on some network-mounted file systems.

@jonocarroll
Copy link
Author

Awesome, thank you for these and for taking the time. Very happy to learn better practices while I learn ... worse practices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment