Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue May 7, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@bart-vanvlerken
Copy link

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
Copy link
Contributor

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

@laresbernardo
Copy link
Collaborator

laresbernardo commented May 8, 2024

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:

  • Wrap the function that generates the warning the first time with suppressWarnings()
  • Install the font as suggested by @bart-vanvlerken (most OS/computers have it installed already)
  • Set up another default (installed) font with Sys.setenv("LARES_FONT" = "AnotherFont")
  • You can also simplify the above suggestion installing a font with sysfonts::font_add_google("Pragati Narrow") (which is a similar font) and setting that new font as default
  • Update lares the latest dev version. You can set Sys.setenv("LARES_FONT" = "ignore") now.

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.

@laresbernardo laresbernardo self-assigned this May 8, 2024
@laresbernardo laresbernardo added the enhancement New feature or request label May 8, 2024
@NumesSanguis
Copy link

NumesSanguis commented May 31, 2024

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: #986

System

  • Debian 11 (Bullseye) in a VM on Google Cloud - Vertex AI
  • Robyn version: ‘3.10.5.9000’
  • R version: 'R version 4.3.3 (2024-02-29)'
  • R commands executed in a Jupyter Lab Notebook
  • Robyn Python libraries installed in a Conda environment and loaded through Sys.setenv(RETICULATE_PYTHON = "/opt/conda/envs/env_name/bin/python")

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
  1. Install ttf-mscorefonts-installer
sudo apt update
sudo apt install ttf-mscorefonts-installer
sudo fc-cache -vr
  1. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants