【问题标题】:How to see the graphical representation of emoji codepoints in R Studio Windows?如何在 R Studio Windows 中查看表情符号代码点的图形表示?
【发布时间】:2026-02-08 11:25:02
【问题描述】:

我在数据框中有一列代码点对应于表情符号。 它们看起来像这样:

1F1E8

我正在使用 remoji 库,但如您所见,我的代码点前面没有 \U,这是本方法所必需的图书馆,据我所知。 示例:

#This works
message (sub_emoji ("This is silly \U1f626"))

#this does not work
message (sub_emoji ("This is silly 1f626"))

我设法做的最多是将代码点转换为 \\U1f626,但它也不起作用。

提前致谢

【问题讨论】:

    标签: rstudio emoji codepoint


    【解决方案1】:

    我尝试的解决方案是将字符串 "\U" 粘贴到代码点的开头,但作为 \ 转义字符我做不到。但是通过一些“技巧”可以做到: 我将所有代码点转换为以下结构(8 个十六进制数字): \\U000xxxxx(如果原始代码点中有 5 个十六进制数字,则为 000) \\U0000xxxx(0000 如果原始代码点中有 4 个十六进制数字)

    我没有深入研究它们的含义(“填充”为 0),但事实是它们的工作方式是相同的,就我所尝试的而言:

    message(sub_emoji("This is silly \U0001f626"))
    This is silly ?
    

    message(sub_emoji("This is silly \U1f626"))
    #This is silly ?
    

    我用 0 “填充”,因为我使用函数 stri_unescape_unicode() 取消转义代码点 \\Uxxxxxxxx 并获得所需的结果 \Uxxxxxxxx(一个 \)将其传递给 sub_emoji() 而这个函数stri_unescape_unicode(),如果代码点有8个十六进制数字,只会给出这个结果(一个\),我没有研究为什么,我只是通过乱来注意到这一点。我还注意到,如果u 是小写字母,它还有另一种效果。 例如:

    #it does not work
    stri_unescape_unicode("\\U1F926")
    #[1] NA
    #Warning message: .....
    
    stri_unescape_unicode("\\U1F926\\U1F3FB")
    #[1] NA
    #Warning message: .....
    
    #it works
    stri_unescape_unicode("\\U0001F926")
    #[1] "\U0001f926"
    stri_unescape_unicode("\\U0001F926\\U0001F3FB")
    # [1] "\U0001f926\U0001f3fb"
    

    一个完整的例子:

    em = stri_unescape_unicode("\\U0001f626")
    message(sub_emoji(paste("This is silly", em)))
    #This is silly ?
    
    emc = stri_unescape_unicode("\\U0001F926\\U0001F3FB")
    message(sub_emoji(paste("This is silly", emc)))
    #This is silly ??
    

    注意最后这个表情,有不同的肤色和发色,有ZWJ Sequence的效果。

    【讨论】:

      最近更新 更多