gpt4 book ai didi

macos - R 到剪贴板在 Mac 上不起作用

转载 作者:行者123 更新时间:2023-12-04 05:37:14 24 4
gpt4 key购买 nike

我已经包装好了 strwrap函数进入 strWrap接受来自剪贴板的文本并自动写入剪贴板。在此,我假设 Mac 的系统名称是 Darwin。此功能适用于 Windows 机器(抱歉,Linux 有太多变化无法实现,而且大多数会使用此功能所适用的软件包的人无论如何都不会是 linux 用户)。

我在 psych 之后建模了我的函数包裹的read.clipboard功能。不幸的是,我让一些人在 talkstats.com 上尝试一下。谁有一台 mac 但它不起作用。我怎样才能使这项工作也适用于 mac?根据 this SO post我的代码似乎也适用于 mac 用户。

如果这按预期工作,它应该能够为 mac 用户从剪贴板读取并在完成后写入剪贴板。我用 # 标记了 mac 特定的行最后为了更容易理解问题

strWrap <-
function(text = "clipboard", width = 70) {
if (text == "clipboard") {
if (Sys.info()["sysname"] == "Darwin") { #
text <- paste(pipe("pbpaste"), collapse=" ")#
} #
if (Sys.info()["sysname"] == "Windows") {
text <- paste(readClipboard(), collapse=" ")
}
}
x <- gsub("\\s+", " ", gsub("\n|\t", " ", text))
x <- strwrap(x, width = width)
if (Sys.info()["sysname"] == "Windows") {
writeClipboard(x, format = 1)
}
if (Sys.info()["sysname"] == "Darwin") { #
j <- pipe("pbcopy", "w") #
cat(x, file = j) #
close(j) #
} #
writeLines(x)
}

X <- "Two households, both alike in dignity, In fair Verona, where we lay
our scene, From ancient grudge break to new mutiny, Where civil blood
makes civil hands unclean. From forth the fatal loins of these two
foes A pair of star-cross'd lovers take their life; Whose
misadventured piteous overthrows Do with their death bury their
parents' strife. The fearful passage of their death-mark'd love, And
the continuance of their parents' rage, Which, but their children's
end, nought could remove, Is now the two hours' traffic of our stage;
The which if you with patient ears attend"

strWrap(X, 70)

最佳答案

pipe返回一个连接对象。您需要从连接中读取。
例如

pcon <- pipe("pbpaste")
text <- paste(scan(pcon, what="character", quiet=TRUE), collapse=" ")
close(pcon)

这适用于我的 Mac。

关于macos - R 到剪贴板在 Mac 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11781121/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com