Skip to content

Instantly share code, notes, and snippets.

@wch
wch / locale.R
Created December 18, 2015 15:31
Multibyte non-UTF-8 locales
# ==== Creating UTF-8 strings ====
# This is how to create a string with UTF-8 encoding. This should work
# regardless of the current locale settings.
x <- rawToChar(as.raw(c(0xe5, 0x8d, 0x88)))
Encoding(x) <- "UTF-8"
x
# [1] "午"
# Another string, 'Δ★😎'
pat <- rawToChar(as.raw(c(0xce, 0x94, 0xe2, 0x98, 0x85, 0xf0, 0x9f, 0x98, 0x8e)))
@wch
wch / shim.R
Last active June 2, 2022 10:39
Shim system.file for htmlwidgets so that a dependent package can be used with devtools::load_all()
shim_system_file <- function(package) {
imports <- parent.env(asNamespace(package))
pkgload:::unlock_environment(imports)
imports$system.file <- pkgload:::shim_system.file
}
shim_system_file("htmlwidgets")
shim_system_file("htmltools")
# After the code above has been run, you can load an in-development package