Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use format=13 on R>=4.2 #63

Merged
merged 1 commit into from
Feb 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions R/win_clipboard.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# Helper function to read from the Windows clipboard
win_read_clip <- function() {
utils::readClipboard()
# On R >= 4.2 (built with UCRT), the default encoding is UTF-8 even on Windows.
# To avoid the encoding mismatch garbles texts, use 13 (CF_UNICODETEXT),
format <- if (identical(R.version$crt, "ucrt")) 13 else 1

utils::readClipboard(format = format)
}

# Helper function to write to the Windows clipboard
win_write_clip <- function(content, object_type, breaks, eos, return_new, ...) {
format <- if (identical(R.version$crt, "ucrt")) 13 else 1

.dots <- list(...)

Expand All @@ -18,7 +23,7 @@ win_write_clip <- function(content, object_type, breaks, eos, return_new, ...) {

# Pass the object to rendering functions before writing out to the clipboard
rendered_content <- render_object(content, object_type, breaks, .dots)
utils::writeClipboard(rendered_content, format = 1)
utils::writeClipboard(rendered_content, format = format)
if (return_new) {
rendered_content
} else {
Expand Down