facebookexperimental / Robyn

Robyn is an experimental, AI/ML-powered and open sourced Marketing Mix Modeling (MMM) package from Meta Marketing Science. Our mission is to democratise modeling knowledge, inspire the industry through innovation, reduce human bias in the modeling process & build a strong open source marketing science community.
https://facebookexperimental.github.io/Robyn/
MIT License
1.07k stars 323 forks source link

Warning message: In .font_global(font, quiet = FALSE, ...) : Font(s) "Arial Narrow" not installed, with other name, or can't be found #973

Open bart-vanvlerken opened 1 month ago

bart-vanvlerken commented 1 month ago

Hi everyone, this error may be familiar to you - I've been getting it a lot. I resolved the warning message as follows:

  1. Download the Ariel Narrow font: https://online-fonts.com/fonts/arial-narrow/download
  2. Place the arielnarrow.ttf file in your working directory
  3. Install and load the sysfonts library
  4. Run font_add(family = 'Ariel Narrow', regular = 'arielnarrow.ttf')
  5. Your code should no longer produce the warning message

This is something that could probably be included/circumvented in the Robyn code, but I hope this helps those looking for a solution.

gufengzhou commented 1 month ago

thanks for the suggestion. @laresbernardo is it a font in lares package? maybe just change to something more standard?

laresbernardo commented 1 month ago

Hi! This is a once-per-session warning to let the user know the font intended to be used in the plots can't be used because it can't be found or it's not installed in your OS. There are a couple of things the user can do:

One of the main benefits of this font usage is that we can add a lot of text in narrower spaces (which for Robyn is quite useful). You'll get nicer and better results if you have the font installed.

NumesSanguis commented 1 month ago

Hi, I'm also facing this issue, but I haven't been able to solve it. Ignoring the error is also not option, because of likely this font issue, the one-pager does not display all info: https://github.com/facebookexperimental/Robyn/issues/986

System

It seems 'Arial Narrow' is a Microsoft font and therefore not included by default on Linux systems.

Workaround with font_add - not working

The suggested workaround by @bart-vanvlerken is not working for me. I executed the commands:

install.packages("sysfonts")
library(sysfonts)
font_add(family = 'Arial Narrow', regular = 'arialnarrow.ttf')

But when executing the commands:

library(Robyn)

plot_adstock(plot = TRUE)
plot_saturation(plot = TRUE)

I'm getting the warning:

Warning message in .font_global(font, quiet = FALSE, ...):
“Font(s) 'Arial Narrow' not installed, with other name, or can't be found”
Warning message in geom_text(aes(x = max(.data$x), y = 0.5, vjust = -0.5, hjust = 1, :
“All aesthetics have length 1, but the data has 900 rows.
ℹ Please consider using `annotate()` or provide this layer with data containing
  a single row.”

Additional attempt

ChatGPT 4o recommended to use showtext as an additional step, but that also didn't help.

install.packages("sysfonts")

# Enable showtext to use custom fonts
library(showtext)  # You might also need this library to use custom fonts easily
showtext_auto()    # Enables automatic use of showtext

After this, this command gives not error, but it still doesn't work with R:

plot(1:10, main = "Example Plot", family = "Arial Narrow")

Other failed attempts

Install Arial fonts

Since ArialNarrow is a Microsoft font? this font is not included by default in a Debian (or other Linux release?). So I tried to install it with ttf-mscorefonts-installer, but that also didn't work:

  1. Add contrib repository to sudo nano /etc/apt/sources.list:
    
    deb http://deb.debian.org/debian bullseye main contrib non-free
    deb-src http://deb.debian.org/debian bullseye main contrib non-free

deb http://deb.debian.org/debian bullseye-updates main contrib non-free deb-src http://deb.debian.org/debian bullseye-updates main contrib non-free

deb http://deb.debian.org/debian bullseye-backports main contrib non-free deb-src http://deb.debian.org/debian bullseye-backports main contrib non-free

deb http://security.debian.org/debian-security/ bullseye-security main contrib non-free deb-src http://security.debian.org/debian-security/ bullseye-security main contrib non-free


2. Install ttf-mscorefonts-installer

sudo apt update sudo apt install ttf-mscorefonts-installer sudo fc-cache -vr


3. Add package `extrafont`

conda activate my_env R install.packages("extrafont")


Then in R:

library(extrafont) font_import() loadfonts() fonts()


It seems `ttf-mscorefonts-installer` does not include 'Arial Narrow'.

### Move ArialNarrow.ttf to fonts folder

sudo cp ArialNarrow.ttf /usr/share/fonts/truetype/msttcorefonts/


R says the font is imported with:

library(extrafont) fonts()



but still `plot_adstock(plot = TRUE)` throws not found error.