Debian Codegraph @

R/compat.r

raw symbols SCIP
1 UNICODE_WARNING <-
2 'Your code contains a unicode char which cannot be displayed in your
3 current locale and R will silently convert it to an escaped form when the
4 R kernel executes this code. This can lead to subtle errors if you use
5 such chars to do comparisons. For more information, please see
6 https://github.com/IRkernel/repr/wiki/Problems-with-unicode-on-windows'
7
8 #' @importFrom utils capture.output
9 warn_unicode_on_windows <- function(code, warn) {
10 # Workaround to warn user when code contains potential problematic code
11 # https://github.com/IRkernel/repr/issues/28#issuecomment-208810772
12 # See https://github.com/hadley/evaluate/issues/66
13 if (.Platform$OS.type == 'windows') {
14 # strip whitespace, because trailing newlines would trip the test...
15 code <- gsub('^\\s+|\\s+$', '', code)
16 real_len <- nchar(code)
17 r_len <- nchar(paste(capture.output(cat(code)), collapse = '\n'))
18 if (real_len != r_len) warn(UNICODE_WARNING)
19 }
20 }