[R] Building Packages.

Jorgen Harmse JH@rm@e @end|ng |rom roku@com
Wed Mar 20 20:26:53 CET 2024


Thank you. tools:::.install_packages works.

It happens that one of the functions in my package is a utility to build packages. I guess I should change the install step.

Regards,
Jorgen.



#' Build package from source

#'

#' \code{roxygen2} & \code{devtools} have several steps to build a package, and

#' \code{build.package} wraps them in one function. It can also clean up

#' and protect the description file.

#'

#' @param package.dir the directory with the package files arranged as expected by

#' \code{roxygen2} except as noted below

#' @param clean whether to remove old \code{Rd} files before starting

#' @param install whether to install the package after building it, which may make the latest

#' version available in the current R session

#'

#' @note The description file should be in \code{DESC.source} rather than \code{DESCRIPTION}.

#' \code{build.package} will then overwrite the machine-generated \code{DESCRIPTION} from the

#' previous build with the true source.

#'

#' @return \code{invisible()}

#'

#' @export



build.package <- function(package.dir,clean=TRUE,install=TRUE)

{ if (!require(roxygen2))

    stop("Please install roxygen2 and its dependencies.")

  if (!require(devtools))

    stop("Please install devtools and its dependencies.")

  if ( file.exists(file.path(package.dir,"DESC.source") -> DESC.source) )

    file.copy(DESC.source, file.path(package.dir,"DESCRIPTION"), overwrite=TRUE)

  roxygenise(package.dir,clean=clean)

  tar <- devtools::build(package.dir)

  if (install)

    install.packages(tar,type='source',repos=NULL)

  invisible()

}



From: Ivan Krylov <ikrylov using disroot.org>
Date: Wednesday, March 20, 2024 at 14:12
To: Jorgen Harmse <JHarmse using roku.com>
Cc: Jorgen Harmse via R-help <r-help using r-project.org>
Subject: [EXTERNAL] Re: [R] Building Packages.
� Wed, 20 Mar 2024 17:00:34 +0000
Jorgen Harmse <JHarmse using roku.com> �����:

> Thank you, but I think I was already using utils.
>
> Regards,
> Jorgen.
>
>
> > environment(install.packages)
>
> <environment: namespace:utils>
>
> > utils::install.packages('/Users/jharmse/Library/CloudStorage/OneDrive-RokuInc/jhBase_1.0.1.tar.gz',type='source',repos=NULL)
> >
>
> Error in library(jhBase) : there is no package called �jhBase�

Sorry, then it has been my mistake to blame RStudio for this.

We can try debugging this. If you start a fresh R process and run
tools:::.install_packages(path_to_tarball), the installation will (try
to) proceed in the current process instead of a child process. Once it
fails, traceback() will be available to show you where the error
condition has been raised. What does it say?

Alternatively,

1. Check the package R files for stray library() calls. Generally,
packages should not be calling library().

2. Try a "binary search" approach. Make a copy of your package code but
remove half of the files (or half of the functions if they live in a
single file). Keep removing a half (or go to the other half) depending
on whether the same error keeps happening.

Good luck!

--
Best regards,
Ivan

	[[alternative HTML version deleted]]



More information about the R-help mailing list