0

I am trying to find the best way to use this pedigree class without using library pedigreemm first.

p1 <- new("pedigree",
          sire = as.integer(c(NA,NA,1, 1,4,5)),
          dam  = as.integer(c(NA,NA,2,NA,3,2)),
          label = as.character(1:6))

Error in getClass(Class, where = topenv(parent.frame())) :
“pedigree” is not a defined class

To be clear, I am trying to do something like base::mean(). However, as the new() function do not belong to the pedigreemm package seems to be not that straightforward. Thus, I can't just do pedigreemm::new(). It is important to highlight that the code works just fine if I load the pedigreemm package first, but I need a way to run without loading it first. Any ideas?

user3091668
  • 2,230
  • 6
  • 25
  • 42
  • Might not be possible... can you explain *why* you need to do this? We may be able to help you find a better solution to the root problem. – Gregor Thomas Feb 20 '19 at 16:56
  • It is a function inside a package. Thus, package::function is always preferred. – user3091668 Feb 20 '19 at 16:58
  • Have you tried to add `@importClassesFrom pedigreemm pedigree` if using `roxygen2`? If the class is defined in another package, then I think the only option available is to import the class. – VFreguglia Feb 20 '19 at 17:22
  • 2
    Also, I don't think using `package::function` is *always* prefered. As an example: if you intend to use `ggplot2` functions in a package, then calling `ggplot2::function` will make the code long and hard to read as you end up using many functions together (i.e. `aes`, `ggplot`, `geom_*`, `scale_*`, etc). While you could import those functions and have a shorter and more legible code. – VFreguglia Feb 20 '19 at 17:28
  • @Freguglia, could you give an example on how to wisely import functions? – user3091668 Feb 20 '19 at 21:31
  • Of course: If you're using `roxygen2`, then simply add a line with `#' @importFrom package function` somewhere in your code. You also need to add the imported package to the `Imports` section in the description file. Here's a related question: https://stackoverflow.com/questions/36574141/r-with-roxygen2-how-to-use-a-single-function-from-another-package – VFreguglia Feb 21 '19 at 02:01

0 Answers0