Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201894

Function imported from dependency not found, requires library(dependency)

$
0
0

I am trying to create an R package that uses functions from another package (gamlss.tr).

The function I need from the dependency is gamlss.dist::TF (gamlss.dist is loaded alongside gamlss.tr), but it is referenced in my code as simply TF within a call to gamlss.tr::gen.trun.

When I load gamlss.tr manually with library(), this works. However, when I rely on the functions of the dependency automatically being imported by my package through @import, I get an "object not found" error as soon as TF is accessed.

My attempt to be more explicit and reference the function I need as gamlss.dist::TF resulted in a different error ("unexpected '::'").

Any tips on how to use this function in my package would be much appreciated!


The code below reproduces the problem if incorporated into a clean R package (as done in this .zip), built and loaded with document("/path/to/package"):

#' @import gamlss gamlss.tr gamlss.dist
NULL

#' Use GAMLSS
#'
#' Generate a truncated distribution and use it.
#' @export

use_gamlss <- function() {
  print("gen.trun():")

  gamlss.tr::gen.trun(par=0,family=TF)
    #Error in inherits(object, "gamlss.family") : object 'TF' not found
  #gamlss.tr::gen.trun(par=0,family=gamlss.dist::TF)
    #Error in parse(text = fname) : <text>:1:1: unexpected '::'
  y = rTFtr(1000,mu=10,sigma=5, nu=5)

  print("trun():")

  truncated_dist = gamlss.tr::trun(par=0,family=TF, local=TRUE)
  model = gamlss(y~1, family=truncated_dist)
  print(model)
}

use_gamlss() will only start working once a user calls library(gamlss.tr).


Viewing all articles
Browse latest Browse all 201894

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>