9  Use of Namespace

In this Quarto book, the author makes a deliberate effort to avoid using library(), in order to keep the user’s search path as clean as possible. Instead, the author uses explicitly namespaced function calls, e.g., pracma::trapz() rather than loading the package with library(pracma) and calling trapz(), so that users can always identify the package from which a function originates.

9.1 library() Call

The author invokes library() only where it is strictly required and cannot be circumvented.

library() on these packages indicates that this is a Quarto book of these packages.

library(survival) in Chapter 2 - Chapter 6 puts the un-exported S3 method survival:::as.data.frame.Surv() on the search path. This is necessary, so that the function spatstat.geom::hyperframe() could recognize a survival, i.e., time-to-event, Surv-column instead of treating it as a matrix-hypercolumn.

library(spatstat.*) in Part S3 Objects & Methods are necessary, so that the function utils::.S3methods() could recognize from which package the S3 methods are defined.

9.2 S3 Methods

9.2.1 Exported from packages base, etc.

The author calls the S3 methods explicitly without namespace, if they are exported from package base, stats, utils, etc. shipped with R version 4.5.2 (2025-10-31). For example, the author uses within.data.frame() instead of

  • within() or
  • base::within() or
  • base::within.data.frame()

Obviously, it is impractical to use `[.data.frame`(cars, 'speed') instead of cars[, 'speed'] or cars$speed in R code-chunks. Readers are expected to be reasonably comfortable with the use of the .Primitive S3 generic functions base::`$` and base::`[`. The author does not explicitly mention the S3 method base::`[.data.frame`() unless required by the context.

9.2.2 Un-exported from packages base, etc.

The author calls the S3 methods by their generic functions without namespace, if they are un-exported from package base, stats, utils, etc. shipped with R version 4.5.2 (2025-10-31). For example, the author uses head() instead of

  • utils::head() or
  • utils:::head.default()

9.2.3 From contributed packages

The author calls the S3 methods explicitly with namespace, no matter they are exported or un-exported from contributed packages other than these packages. For example,

  • the author uses spatstat.geom::with.hyperframe() instead of
    • library(spatstat.geom); with.hyperframe(), or
    • library(spatstat.geom); with().
  • the author uses spatstat.geom::print.ppp() instead of
    • library(spatstat.geom); print.ppp(), or
    • library(spatstat.geom); print(), or
    • library(spatstat.geom); (.)

Obviously, it is impractical to use

spatstat.data::flu |>
  spatstat.geom::`$.hyperframe`(name = 'pattern')

instead of spatstat.data::flu$pattern. For this use,

  • Readers are expected to be reasonably comfortable with the use of the .Primitive S3 generic function base::`$`.
  • The author explicitly mentions the S3 method spatstat.geom::`$.hyperframe`() in the surrounding text if necessary.

9.2.4 From these packages

The author calls the S3 methods by their generic functions without namespace, if they are defined in these packages. For example, the author uses library(groupedHyperframe) and the .Primitive S3 generic function base::log() in Section 27.3, instead of

  • library(groupedHyperframe); log.ppp() or
  • groupedHyperframe::log.ppp().

All S3 methods defined in these packages are exported.

9.3 Data Sets

The author makes a deliberate effort to reference data sets using their full namespaces.

9.3.1 From package datasets

The author calls the data from package datasets shipped with R version 4.5.2 (2025-10-31) with namespace datasets::. For example, the author uses datasets::penguins instead of

  • penguins or
  • data('penguins', package = 'datasets'); penguins

9.3.2 From contributed packages

The author calls the data from contributed packages other than these packages with the corresponding namespace. For example, the author uses spatstat.data::ants instead of

  • library(spatstat.data); ants or
  • data('ants', package = 'spatstat.data'); ants

9.3.3 From these packages

The author calls the data from these packages with the corresponding namespace. For example, the author uses groupedHyperframe::Ki67 in Chapter 5, instead of

  • library(groupedHyperframe); Ki67 or
  • data('Ki67', package = 'groupedHyperframe'); Ki67