Bug 17352 - strwidth uses wrong default font
Summary: strwidth uses wrong default font
Status: UNCONFIRMED
Alias: None
Product: R
Classification: Unclassified
Component: Graphics (show other bugs)
Version: R 3.4.1
Hardware: All All
: P5 normal
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2017-10-11 01:48 UTC by Karl Millar
Modified: 2018-06-18 23:14 UTC (History)
1 user (show)

See Also:


Attachments
Patch to fix the bug (792 bytes, patch)
2017-10-11 01:48 UTC, Karl Millar
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Karl Millar 2017-10-11 01:48:29 UTC
Created attachment 2302 [details]
Patch to fix the bug

According to the docs, in calls to strheight and strwidth, if 'font' isn't specified it uses the value from par().  It seems to use the 'normal' font instead.


> par(font = 1)
> strwidth("m", units="fig")
[1] 0.01983333
> par(font = 2)
> strwidth("m", units="fig")  # Should return 0.02116667
[1] 0.01983333
> strwidth("m", units="fig", font = 2)
[1] 0.02116667

I've attached a patch which fixes this issue.
Comment 1 Paul Murrell 2018-06-18 22:22:16 UTC
I agree that the behaviour you describe seems more desirable, but just checking where in "the docs" you are referring to that says "if 'font' isn't specified it uses the value from par()"
Comment 2 Karl Millar 2018-06-18 22:38:39 UTC
In help("strwidth"):

font, vfont, ...: additional information about the font, possibly
          including the graphics parameter ‘"family"’: see ‘text’.


In help("text"):

col, font: the color and (if ‘vfont = NULL’) font to be used, possibly
          vectors.  These default to the values of the global graphical
          parameters in ‘par()’.
Comment 3 Paul Murrell 2018-06-18 23:01:11 UTC
Cool.  Thanks.  Just checking I wasn't missing something you were seeing :)
Comment 4 Paul Murrell 2018-06-18 23:14:40 UTC
Fixed in r-devel (r74914).  Thanks!