Giter Club home page Giter Club logo

Comments (5)

ampu3ro avatar ampu3ro commented on September 23, 2024 6

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.

petrbouchal avatar petrbouchal commented on September 23, 2024 2

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.

wch avatar wch commented on September 23, 2024

Hm... For your package to work, you can:

from extrafont.

wangyuchen avatar wangyuchen commented on September 23, 2024

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.

JanaJarecki avatar JanaJarecki commented on September 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.