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

Windows clipbaord functions need format = 13 on R >= 4.2 #62

Closed
yutannihilation opened this issue Jan 31, 2022 · 1 comment · Fixed by #63
Closed

Windows clipbaord functions need format = 13 on R >= 4.2 #62

yutannihilation opened this issue Jan 31, 2022 · 1 comment · Fixed by #63
Assignees

Comments

@yutannihilation
Copy link
Contributor

yutannihilation commented Jan 31, 2022

You know, the upcoming R 4.2 for Windows will support UTF-8 as native encoding.

c.f. https://blog.r-project.org/2021/12/07/upcoming-changes-in-r-4.2-on-windows/index.html

While this itself is a very great change, this causes a possible mismatch between the system's encoding and R's encoding. Currently, the default of format argument is 1, which means (from ?clipboard):

CF_TEXT	1	Text in the machine's locale

but R uses UTF-8. Because of this gap, the texts will get garbled like this: tidyverse/reprex#406

To avoid the problem, we need to specify 13, which means unicode (UTF-16).

CF_UNICODETEXT	13	Text in Unicode (UCS-2)

By choosing this, the R's connection API will converts the text from / to R strings properly (I don't understand the mechanism, but it seems to work so. c.f., https://bugs.r-project.org/show_bug.cgi?id=18267). Actually, this is the recommended setting by ?clipboard:

It is recommended to use Unicode text instead of text to avoid interoperability problems. (Note that R 4.2 and newer on recent systems uses UTF-8 as the native encoding but the machine's locale uses a different encoding.)

@mdlincoln
Copy link
Owner

Thank you very much for the report and PR 🥂 I will be able to review it a bit later this week.

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Apr 14, 2022
## clipr 0.8.0

- Add handlers for using the clipboard on systems using [Wayland]
  (https://wayland.freedesktop.org/) via
  [wl-clipboard](https://github.com/bugaevc/wl-clipboard).
  Thank you to @nacnudus for the PR.

- For R >= 4.2, `write_clip()` calls on Windows are modified to work
  well with R's shift to supporting UTF-8 as a native encoding on Windows.
  Thank you to @yutannihilation for the PR. Read more here:
  <mdlincoln/clipr#62>

- Moved CI off of Travis and on to GitHub Actions

- Clipr now has a pkgdown site at <https://matthewlincoln.net/clipr/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants