Comments (5)
I just ran into this issue as well. I believe it happens because loadfonts()
calls pdfFonts()
postscriptFonts()
or windowsFonts()
without specifying that they come from the grDevices
package environment. Until it's modified internally, you can specify the function explicitly like
.onLoad <- function(libname,pkgname) {
pdfFonts <- grDevices::pdfFonts
extrafont::loadfonts("pdf",quiet=T)
}
Alternatively, you could require(grDevices)
but devtools::check()
notes that you shouldn't
from extrafont.
FWIW I ended up doing the below, with extrafont
in Imports - overall it is an adaptation of the code in hrbrthemes
, with added *Fonts <- grDevices::*Fonts
calls for each "missing" function.
It now passed the Windows and Mac checks on r-hub without warnings, and likewise for the MacOS on my Mac (the Fedora and Linux rhub builds fails because of errors in building other dependencies). Without the additions, the package fails to load during Windows rhub check, returning the error reported by @wangyuchen.
I still don't know what I am missing given that e.g. hrbrthemes passes CRAN checks without the extra grDevices lines...
.onAttach <- function(libname, pkgname) {
# adapted from hrbrthemes
# Suggestion by @alexwhan
if (.Platform$OS.type == "windows") { # nocov start
# fix as per https://github.com/wch/extrafont/issues/44#issue-comment-box
windowsFonts <- grDevices::windowsFonts
if (interactive()) packageStartupMessage("Registering Windows fonts with R")
extrafont::loadfonts("win", quiet = TRUE)
}
if (getOption("reschola.loadfonts", default = FALSE)) {
if (interactive()) packageStartupMessage("Registering PDF & PostScript fonts with R")
# fix as per https://github.com/wch/extrafont/issues/44#issue-comment-box
pdfFonts <- grDevices::pdfFonts
postscriptFonts <- grDevices::postscriptFonts
extrafont::loadfonts("pdf", quiet = TRUE)
extrafont::loadfonts("postscript", quiet = TRUE)
}
fnt <- extrafont::fonttable()
if (!any(grepl("Roboto|Roboto[ ]Condensed", fnt$FamilyName))) {
packageStartupMessage("NOTE: Roboto and Roboto Condensed fonts are required for the default setting of theme_schola() to work.")
packageStartupMessage(" Please use reschola::import_fonts() to install Roboto and Roboto Condensed")
} # nocov end
}
from extrafont.
Hm... For your package to work, you can:
- Add extrafont do the
Depends
field. - Put
require(extrafont)
in your function. - Run the same
loadfonts()
commands that are contained inextrafont:::.onAttach
: https://github.com/wch/extrafont/blob/master/R/aaa.r
from extrafont.
Thanks!
It seems like the first two options are not usually recommended, so I decided I should add the loadfonts()
to somewhere in my package.
I tried adding it to the function that need to use fonts, but it seems strange it will load fonts while what I really want is to use some fonts. Also, it will generate warnings when I check()
the package because I guess when checking, the function doesn't run.
Then I tried add it to my own .onAttach()
, it worked fine, but when I check package, the check failed when loading NAMESPACE with the following error:
Error : .onAttach failed in attachNamespace() for 'alt005', details:
call: get(as.character(FUN), mode = "function", envir = envir)
error: object 'pdfFonts' of mode 'function' was not found
Error: package or namespace load failed for 'alt005'
Execution halted
Should I try adding it to other places or should I just use require(extrafont)
?
from extrafont.
Hi guys,
is there any update on this issue? I have trouble inserting the initialization of a font into the .onLoad() function of my package.
best
Jana
from extrafont.
Related Issues (20)
- Easy speed-up possible? HOT 1
- No Fontname. Skipping, for all of my fonts in Windows? HOT 1
- package ‘extrafonts’ is not available (for R version 4.0.2) HOT 1
- `argument is of length zero` error in `afm_scan_files`
- wish: sort `fonts()` alphabetically HOT 1
- new font is ignored
- Using extrafont within knitr to pdf HOT 1
- windowFonts() not recognized in .Rprofile HOT 3
- how to install the font of "Young" in Mac?
- "GhostScript was not found" on M1 Big Sur Mac HOT 2
- Correctly finds font directory, but says "No FontName. Skipping" for all fonts HOT 29
- font_import segfaults. HOT 3
- a problem when I ues font_import
- Installing a font from .otf/.ttf files
- Seek replacement for `ttf2pt1` for extracting font metrics HOT 2
- "Found FontName for 0 fonts." on 64-bit Windows OS
- Type1 importing not working
- Can´t load dinpro light
- Font embedding not working due to GhostScript `-I` switch
- Font is embeded, but i can not document properly
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from extrafont.