有时我使用 R 从 pdf 中解析文本以获取撰写文章时的引用(我使用 LATEX)。我想做的一件事是将左右引号更改为 LATEX 样式的左右引号。
LATEX 会变成"dog"
(``dog''
所以两个 ` 代表左边,两个 ' 代表右边)
这是我拥有的和想要获得的示例。
#currently
x <- c('I like "proper" cooking.', 'I heard him say, "I want some too" and "nice".')
[1] "I like \"proper\" cooking." "I heard him say, \"I want some too\" and \"nice\"."
#desired outcome
[1] "I like ``proper'' cooking." "I heard him say, ``I want some too'' and ``nice''."
编辑:以为我会分享上下文的实际用途。使用 ttmaccer 的解决方案(适用于 Windows 机器):
g <- function(){
require(qdap)
x <- readClipboard()
x <- clean(paste2(x, " "))
zz <- mgsub(c("- ", "“", "”"), c("", "``", "''"), x)
zz <- gsub("\"([^\"].*?)\"","``\\1''", zz)
writeClipboard(noquote(zz), format = 1)
}
注意:qdap
可以在这里下载