Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8386219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:52:33+00:00 2026-06-09T17:52:33+00:00

I’m working on being able to read transcripts of dialogue into R. However I

  • 0

I’m working on being able to read transcripts of dialogue into R. However I run into a bump with special characters like curly quotes en and em dashes etc. Typically I replace these special characters in a microsoft product first with replace. Typically I replace special characters with plain text but on some occasions desire to replace them with other characters (ie I replace “ ” with { }). This is tedious and not always thorough. If I could read the transcripts into R as is and then use Encoding to switch their encoding to a recognizable unicode format, I could gsub them out and replace them with plain text versions. However the file is read in in some way I don’t understand.
Here’s an xlsx of what my data may look like:

http://dl.dropbox.com/u/61803503/test.xlsx

This is what is in the .xlsx file

text                              num
“ ” curly quotes                    1
en dash (–) and the em dash (—)     2
‘ ’ curly apostrophe-ugg            3
…  ellipsis are uck in R            4

This can be read into R with:

URL <- "http://dl.dropbox.com/u/61803503/test.xlsx"
library(gdata) 
z <- read.xls(URL, stringsAsFactors = FALSE) 

The result is:

                                 text num
1                “ †curly quotes    1
2 en dash (–) and the em dash (—)   2
3        ‘ ’ curly apostrophe-ugg   3
4          …  ellipsis are uck in R   4

So I tried to use Encoding to convert to Unicode:

iconv(z[, 1], "latin1", "UTF-8")

This gives:

[1] "â\u0080\u009c â\u0080\u009d curly quotes"                "en dash (â\u0080\u0093) and the em dash (â\u0080\u0094)"
[3] "â\u0080\u0098 â\u0080\u0099 curly apostrophe-ugg"        "â\u0080¦  ellipsis are uck in R"     

Which makes gsubing less useful.

What can I do to convert these special characters to distinguishable unicode so I can gsub them out appropriately? To be more explicit I was hoping to have z[1, 1] read:

\u201C 2\u01D curly quotes

To make it even more clear my desired outcome I will webscrape the tables from a page like wikipedia’s: http://en.wikipedia.org/wiki/Quotation_mark_glyphs and use the unicode reference chart to replace characters appropriately. So I need the characters to be in unicode or some standard format that I can systematically go through and replace the characters. Maybe it already is and I’m missing it.

PS I don’t save the files as .csv or plain text because the special characters are replaced with ? hence the use of read.xls I’m not attached to any particular method of reading in the file (ie read.xls) if you’ve got a better alternative.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:52:35+00:00Added an answer on June 9, 2026 at 5:52 pm

    Maybe this will help (I’ll have access to a Windows machine tomorrow and can probably play with it more at that point if SO doesn’t get you the answer first).

    On my Linux system, when I do the following:

    iconv(z$text, "", "cp1252")
    

    I get:

    [1] "\x93 \x94 curly quotes"                "en dash (\x96) and the em dash (\x97)"
    [3] "\x91 \x92 curly apostrophe-ugg"        "\x85  ellipsis are uck in R"  
    

    This is not UTF, but (I believe) ISO hex entities. Still, if you are able to get to this point also, then you should be able to use gsub the way you intend to.

    See this page (reserved section in particular) for conversions.

    Update

    You can also try converting to an encoding that doesn’t have those characters, like ASCII and set sub to "byte". On my machine, that gives me:

    iconv(z$text, "", "ASCII", "byte")
    # [1] "<e2><80><9c> <e2><80><9d> curly quotes"               
    # [2] "en dash (<e2><80><93>) and the em dash (<e2><80><94>)"
    # [3] "<e2><80><98> <e2><80><99> curly apostrophe-ugg"       
    # [4] "<e2><80><a6>  ellipsis are uck in R"   
    

    It’s ugly, but UTF-8(e2, 80, 9c) is a right curly quote (each character, I believe, is a set of three values in angled brackets). You can find conversions at this site where you can search by punctuation mark name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I need a function that will clean a strings' special characters. I do NOT
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.