[R-lang] Re: Embedding phonetic symbols in R

Donald Derrick dderrick@interchange.ubc.ca
Wed Jul 20 17:08:56 PDT 2011


I use a mac, so I can't be sure this works in windows, but...  Here's my very simple demo:

tryCatch(par(family="Doulos SIL"),error=par(family="serif"))
plot(1,1,xlab="\u027D",ylab="\u027E")

It is a nonsense graph, but it works.  

Even better, you can just type in the fonts in unicode (here's hoping they show up in the thread right when I email it!)

tryCatch(par(family="Doulos SIL"),error=par(family="serif"))
plot(1,1,xlab="ɽ",ylab="ɾ")

DD

On 2011-07-20, at 4:45 PM, Sverre Stausland wrote:

> Hi Donald,
> 
> if someone else has the same problem later, I think it would be a good
> idea to keep this thread alive in R-lang. Here's an easy reproducible
> example which does not work for me:
> 
>> windowsFonts(IPA="TT Doulos SIL")
>> tryCatch(par(family="IPA"),error=par(family="serif"))
>> pdf("C:/test.pdf",family="serif")
>> plot.new()
>> plot.window(xlim=c(0,1),ylim=c(0,1))
>> text(x=.5,y=.5,labels="\u027D",family="IPA",cex=5)
> Error in text.default(x = 0.5, y = 0.5, labels = "<U+027D>", family = "IPA",  :
>  Invalid font type
> In addition: Warning messages:
> 1: In text.default(x = 0.5, y = 0.5, labels = "<U+027D>", family = "IPA",  :
>  font family not found in PostScript font database
> 
> Are you using R in Windows, by the way?
> 
> Sverre
> 
> On Wed, Jul 20, 2011 at 7:26 PM, Donald Derrick
> <dderrick@interchange.ubc.ca> wrote:
>> Put it at the beginning of the program in question.  It is just a parameter that selects the fonts used in future pdf or quartz outputs.
>> 
>> If that does not work for you, email me direct and I'll take a look at your particular example.
>> 
>> DD
>> 
>> On 2011-07-20, at 4:21 PM, Sverre Stausland wrote:
>> 
>>> Hi Donald,
>>> 
>>> could you be a little bit more specific? When creating a pdf, when
>>> should this call be made?
>>> 
>>> Best
>>> Sverre
>>> 
>>> On Wed, Jul 20, 2011 at 7:14 PM, Donald Derrick
>>> <dderrick@interchange.ubc.ca> wrote:
>>>> I just use code like:
>>>> tryCatch(par(family="Doulos SIL"),error=par(family="sans"))
>>>> If you don't like/have "Doulos SIL", pick another font.  Same with the
>>>> fallback font.
>>>> 
>>>> 
>>>> DD
>>>> 
>>>> On 2011-07-20, at 4:06 PM, Bill Poser wrote:
>>>> 
>>>> I hesitate to recommend this technique, but if you are really stuck you
>>>> could try directly hacking the postscript as described in this post from the
>>>> time before R supported Unicode:
>>>> http://babel.ling.upenn.edu/phonetics/archive/Unicode%20in%20R%20Text.htm
>>>> 
>>>> On Wed, Jul 20, 2011 at 12:50 PM, Sverre Stausland <johnsen@fas.harvard.edu>
>>>> wrote:
>>>>> 
>>>>> Hi Roger,
>>>>> 
>>>>> I've actually seen that thread before, but the only thing I extracted
>>>>> from it was "use Cairo", which I did ... There are some remaining
>>>>> details to be sorted out, I just don't know what they are.
>>>>> 
>>>>> Sverre
>>>>> 
>>>>> On Wed, Jul 20, 2011 at 3:47 PM, Levy, Roger <rlevy@ucsd.edu> wrote:
>>>>>> Hi Sverre,
>>>>>> 
>>>>>> You might find the following thread useful:
>>>>>> 
>>>>>> 
>>>>>>  http://pidgin.ucsd.edu/pipermail/r-lang/mailman.ucsd.edu/pipermail/ling-r-lang-l/2010-October/000110.html
>>>>>> 
>>>>>> For me a crucial part of the puzzle was using the cairo_pdf and cairo_ps
>>>>>> drivers (kudos to Paul Metzner for pointing this out).
>>>>>> 
>>>>>> Best & let us know if that helps!
>>>>>> 
>>>>>> Roger
>>>>>> 
>>>>>> On Jul 20, 2011, at 1:33 PM, Sverre Stausland wrote:
>>>>>> 
>>>>>>> Hi all,
>>>>>>> 
>>>>>>> I'm sure I'm not the only Windows user out there trying to embed IPA
>>>>>>> symbols in R graphics and then make a pdf out of it. If anyone knows
>>>>>>> how to do that, I would appreciate some help. Because I have not
>>>>>>> succeeded.
>>>>>>> 
>>>>>>> Here is what I have tried. I'm creating a plot in R with IPA phonetic
>>>>>>> symbols, using the standard
>>>>>>> font Doulos SIL
>>>>>>> 
>>>>>>> (http://scripts.sil.org/cms/scripts/page.php?item_id=DoulosSILfont&_sc=1)
>>>>>>> 
>>>>>>> When attempting to create a pdf of this plot in R using the pdf()
>>>>>>> function, I will get the following error messages:
>>>>>>> 
>>>>>>>> pdf(file="C:/~myplot.pdf")
>>>>>>>> plot.default(my.x,my.y,type="n")
>>>>>>>> windowsFonts(IPA="TT Doulos SIL")
>>>>>>>> text(my.x,my.y,labels=my.data$words.with.IPA,family="IPA")
>>>>>>> Error in text.default(my.x, my.y,  :
>>>>>>> Invalid font type
>>>>>>> In addition: Warning messages:
>>>>>>> 1: In text.default(my.x, my.y,  :
>>>>>>> font family not found in PostScript font database
>>>>>>> 
>>>>>>> I've been advised that I can resolve this problem using the Cairo
>>>>>>> package for R. But I have not succeeded. Here is my call:
>>>>>>> 
>>>>>>>> library(Cairo)
>>>>>>>> CairoPDF(file="C:/~myplot.pdf")
>>>>>>>> plot.default(my.x,my.y,type="n")
>>>>>>>> windowsFonts(IPA="TT Doulos SIL")
>>>>>>>> text(my.x,my.y,labels=my.data$words.with.IPA,family="IPA")
>>>>>>>> dev.off()
>>>>>>> 
>>>>>>> It produces a pdf file, but all the IPA symbols come out as boxes.
>>>>>>> 
>>>>>>> Please note that R has no difficulties producing this plot in its
>>>>>>> graphic window with IPA symbols. It's only the pdf output I'm having
>>>>>>> difficulties with.
>>>>>>> 
>>>>>>> Any help would be appreciated! Further details follow below.
>>>>>>> 
>>>>>>>> sessionInfo()
>>>>>>> R version 2.13.1 (2011-07-08)
>>>>>>> Platform: i386-pc-mingw32/i386 (32-bit)
>>>>>>> 
>>>>>>> locale:
>>>>>>> [1] LC_COLLATE=English_United States.1252
>>>>>>> [2] LC_CTYPE=English_United States.1252
>>>>>>> [3] LC_MONETARY=English_United States.1252
>>>>>>> [4] LC_NUMERIC=C
>>>>>>> [5] LC_TIME=English_United States.1252
>>>>>>> 
>>>>>>> attached base packages:
>>>>>>> [1] stats     graphics  grDevices utils     datasets  methods   base
>>>>>>> 
>>>>>>> other attached packages:
>>>>>>> [1] Cairo_1.4-9
>>>>>>> 
>>>>>>> loaded via a namespace (and not attached):
>>>>>>> [1] tools_2.13.1
>>>>>>> 
>>>>>>>> Sys.getlocale()
>>>>>>> [1] "LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
>>>>>>> States.1252;LC_MONETARY=English_United
>>>>>>> States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252"
>>>>>> 
>>>>>> --
>>>>>> 
>>>>>> Roger Levy                      Email: rlevy@ucsd.edu
>>>>>> Assistant Professor             Phone: 858-534-7219
>>>>>> Department of Linguistics       Fax:   858-534-4789
>>>>>> UC San Diego                    Web:   http://idiom.ucsd.edu/~rlevy
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>> 
>>>> 
>>>> 
>>>> 
>> 
>> 
>> 




More information about the ling-r-lang-L mailing list