简体   繁体   English

导出软件包的Unicode字符

[英]Export unicode characters for package

I made a function that removes en and em dashes. 我做了一个删除en和em破折号的函数。 Great! 大! But when I try to upload it to github and then re-install as a package something happens to the function. 但是,当我尝试将其上传到github,然后以软件包的形式重新安装时,功能发生了变化。 It replaces the dashes with some gobly gook characters. 它用一些让人毛骨悚然的傻瓜字符代替了破折号。 That usually means unicode stuff. 这通常意味着unicode的东西。 I want to be able to export the function. 我希望能够导出该功能。

I tried replacing \\\\– with \– and 0x2013 . 我尝试用\–0x2013替换\\\\– Also played with fixed and perl arguments. 也可以使用fixedperl参数。 No luck. 没运气。

Here's: 这里是:

  1. the function that works 起作用的功能
  2. a test case 一个测试案例
  3. how it looks after I import it back in 将其重新导入后的外观

Code: 码:

#What I exported
incomp <- function (text.var){
    x <- gsub("\\–", "|", x)
    x <- gsub("\\—", "|", x)
    return(x)
}

#here it is in action working well
x <- c("I like...", "well?.", "–", "—")
incomp(x)

#[1] "I like..." "well?."    "|"  "|"   #what I look like (ain't I pretty?)

#what the exported function looks like when the package compiles
incomp <- function (text.var){   
    x <- gsub("[–]", "|", x)
    x <- gsub("[—]", "|", x)
    return(x)
}

#I don't work anymore
x <- c("I like...", "well?.", "(–", "—")   #I'm broken
incomp(x)

A search for r and unicode brings up lots of information but I can't seem to apply it to my situation correctly. 搜索r和unicode会带来很多信息,但是我似乎无法正确地将其应用于我的情况。

The unicodes are : unicode是

  • u2013 for the en dash u2013 for the dash
  • u2014 for the em dash u2014 for破折号

This post is cross posted at talkstats.com. 此帖子交叉发布在talkstats.com。 I generally do not cross post but am under the gun to get this out. 我通常不会越过哨所,但会竭尽全力解决这个问题。 I will link the two threads. 我将链接两个线程。 LINK TO THE TALKSTATS THREAD 链接到TALKSTATS线程

Thank you in advance. 先感谢您。

The default when exporting locale of R are set to "C" I guess. 我想导出R的语言环境时的默认设置为“ C”。 Your locale maybe different. 您的语言环境可能有所不同。 Perhaps you can use Sys.setlocale in your package? 也许您可以在包中使用Sys.setlocale?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM