laresbernardo / lares

Analytics & Machine Learning R Sidekick
https://laresbernardo.github.io/lares/
233 stars 49 forks source link

font_exist is false if ttf file in subdir #53

Closed louisjanin closed 7 months ago

louisjanin commented 7 months ago

Hi Bernardo,

I use Robyn for my company and tried to fix the warning "Arial Narrow not installed". I came accross the font_exists function from the lares package and I think my problem was that the font was installed but inside a nested directory. So what I did was copy it in /usr/share/fonts which fixed the problem for me:

rproc-00:/usr/share/fonts# ls
'Arial Narrow.ttf'   cmap   cMap   fonts-go   opentype   truetype   type1   woff   X11
rproc-00:/usr/share/fonts# ls truetype/msttcorefonts/Arial*
 truetype/msttcorefonts/Arial_Black.ttf         truetype/msttcorefonts/Arial_Italic.ttf
 truetype/msttcorefonts/Arial_Bold_Italic.ttf  'truetype/msttcorefonts/Arial Narrow Regular.ttf'
 truetype/msttcorefonts/Arial_Bold.ttf          truetype/msttcorefonts/Arial.ttf

So i just wanted to let you know, because maybe the function could look in subdirs.. Thanks and sorry for the not so well formatted issue...

laresbernardo commented 7 months ago

Hi @louisjanin thanks for reporting this issue and for sharing you're also using Robyn :)

What OS are you at? Can you share your R.version$os? (Probably linux-gnu)

Also, notice /usr/share/fonts/ is included in the code to check the fonts, so that's why it gets fixed.

Would love for it to work for you but given I have no access to your OS, I can't debug for you. Would be great if you could help me with this.

On the other hand, FYI, to turn off this notification (it'll only pop once per session), you can set Sys.unsetenv("LARES_FONT").

laresbernardo commented 7 months ago

I've just enabled a parameter called font_dirs that can be passed to font_exists() to test and to theme_lares() as well. It looks out for custom directories (like yours: ~/truetype/msttcorefonts/) for fonts. Can you please try and see how it goes? Not sure it'll work for Robyn yet but this is a first step.

louisjanin commented 7 months ago

Indeed R.version$os is linux-gnu on my install Sorry I couldnt properly test font_dirs, does this not get the right latest version ?

remotes::install_github("laresbernardo/lares")

Here's what I get

> font_exists('Arial Narrow', font_dirs='/usr/share/fonts/truetype')
Error in font_exists("Arial Narrow", font_dirs = "/usr/share/fonts/truetype") : 
  unused argument (font_dirs = "/usr/share/fonts/truetype")
laresbernardo commented 7 months ago

Yes, that's right. But you must refresh your R session before you load the latest version and retry.

> font_exists('Arial Narrow', font_dirs='/usr/share/fonts/truetype')
[1] TRUE
louisjanin commented 7 months ago

It works! Now I just do this and it seems to work fine :1st_place_medal:

library(Robyn)
lares::theme_lares(font_dirs="/usr/share/fonts/truetype")
laresbernardo commented 7 months ago

Amazing, thanks for confirming.