Re: [R-pkg-devel] R-package-devel Digest, Vol 105, Issue 19

2024-01-24 Thread Simon Urbanek
This is a reminder why one should never build packages directly in their source 
directory since it can only be done once (for packages with native source code) 
- always use

R CMD build --no-build-vignettes foo && R CMD INSTALL foo_*.tar.gz

if you plan to edit files in the source directory and re-use it.

Cheers,
Simon


> On 25/01/2024, at 8:34 AM, Carl Schwarz  wrote:
> 
> Solved...
> 
> The src/ directory also included a .o and .so objects from the last build
> of the package that must be "out of date" because once I removed those
> older objects, the Build -> Document and build -> Check package now work
> fine without crashing...A newer version of the .o and .so objects are now
> built and it now works fine.
> 
> Thanks
> Carl Schwarz
> 
> On Wed, Jan 24, 2024 at 10:57 AM Carl Schwarz 
> wrote:
> 
>> Thanks for your suggestions.  I followed the suggestion in today's message
>> (see results below) which all run without issue.
>> I tried to isolate the problem more
>> 
>> The issue appears to be with load_dll()
>> 
>> When I try
>>> getwd()
>> [1] "/Users/cschwarz/Library/CloudStorage/Dropbox/SPAS-R/SPAS"
>>> load_dll()
>> 
>> It crashes.
>> 
>> 
>> I moved the package outside of CloudStorage to see if that is the issue.
>>> getwd()
>> [1] "/Users/cschwarz/Desktop/SPAS"
>>> load_dll()
>> 
>> It crashes.
>> 
>> 
>> I tried doing a dll_load() where there is NO c++ object, i.e. a random
>> directory and it terminates with a sensible error message
>>> setwd("/Users/cschwarz/Desktop/BikePics")
>>> library(pkgload)
>>> load_dll()
>> Error in `value[[3L]]()`:
>> ! Could not find a root 'DESCRIPTION' file that starts with '^Package' in
>> /Users/cschwarz/Desktop/BikePics.
>> ℹ Are you in your project directory and does your project have a
>> 'DESCRIPTION' file?
>> Run `rlang::last_trace()` to see where the error occurred.
>> 
>> I'm following the suggestions on including TMB code in a package at
>> 
>> https://stackoverflow.com/questions/48627069/guidelines-for-including-tmb-c-code-in-an-r-package
>> and appear to have all the necessary files
>> 
>> I created my own load_dll() function by copying over the code and adding a
>> browser().
>> It appears to run fine until the statement library.dynam2(path.lib) where
>> it cannot find the function library.dynam2
>> 
>> 
>>> my_load_dll()
>> Called from: my_load_dll()
>> Browse[1]> n
>> debug at #4: package <- pkg_name(path)
>> Browse[2]> n
>> debug at #5: env <- ns_env(package)
>> Browse[2]> n
>> debug at #6: nsInfo <- parse_ns_file(path)
>> Browse[2]> n
>> debug at #7: dlls <- list()
>> Browse[2]> n
>> debug at #8: dynLibs <- nsInfo$dynlibs
>> Browse[2]> n
>> debug at #9: nativeRoutines <- list()
>> Browse[2]> n
>> debug at #10: for (i in seq_along(dynLibs)) {
>>lib <- dynLibs[i]
>>dlls[[lib]] <- library.dynam2(path, lib)
>>routines <- assignNativeRoutines(dlls[[lib]], lib, env,
>> nsInfo$nativeRoutines[[lib]])
>>nativeRoutines[[lib]] <- routines
>>if (!is.null(names(nsInfo$dynlibs)) &&
>> nzchar(names(nsInfo$dynlibs)[i]))
>>env[[names(nsInfo$dynlibs)[i]]] <- dlls[[lib]]
>>setNamespaceInfo(env, "DLLs", dlls)
>> }
>> Browse[2]> n
>> debug at #11: lib <- dynLibs[i]
>> Browse[2]> n
>> debug at #12: dlls[[lib]] <- library.dynam2(path, lib)
>> Browse[2]> n
>> Error in library.dynam2(path, lib) :
>>  could not find function "library.dynam2"
>> 
>> I'm unable to find where the library.dynam2() function lies... A google
>> search for library.dynam2 doesn't show anything except for a cryptic
>> comment in
>> https://rdrr.io/cran/pkgload/src/R/load-dll.R
>> which says
>> 
>> ## The code below taken directly from base::loadNamespace
>>  ## 
>> https://github.com/wch/r-source/blob/tags/R-3-3-0/src/library/base/R/namespace.R#L466-L485
>>  ## except for the call to library.dynam2, which is a special version of
>>  ## library.dynam
>> 
>> This is now beyond my pay grade..
>> 
>> Suggestions?
>> 
>> 
>> --
>> 
>> From James Lamb 
>> 
>> Using the shell:
>> 
>> R CMD build .
>> - success with
>> 
>> * checking for file ‘./DESCRIPTION’ ... OK
>> 
>> * preparing ‘SPAS’:
>> 
>> * checking DESCRIPTION meta-information ... OK
>> 
>> * cleaning src
>> 
>> * installing the package to build vignettes
>> 
>> * creating vignettes ... OK
>> 
>> * cleaning src
>> 
>> * checking for LF line-endings in source and make files and shell scripts
>> 
>> * checking for empty or unneeded directories
>> 
>> * building ‘SPAS_2024.1.31.tar.gz’
>> 
>> 
>> R CMD INSTALL --with-keep.source ./SPAS_*.tar.gz
>> - success. Lots of warning from the C compiler but appears to terminate
>> successfully with
>> 
>> 
>> installing to /Users/cschwarz/Rlibs/00LOCK-SPAS/00new/SPAS/libs
>> 
>> ** R
>> 
>> ** inst
>> 
>> ** byte-compile and prepare package for lazy loading
>> 
>> ** help
>> 
>> *** installing help indices
>> 
>> ** building package indices
>> 
>> ** installing vignettes
>> 
>> ** testing if installed package can be loaded from 

Re: [R-pkg-devel] R-package-devel Digest, Vol 105, Issue 19

2024-01-24 Thread Carl Schwarz
Solved...

The src/ directory also included a .o and .so objects from the last build
of the package that must be "out of date" because once I removed those
older objects, the Build -> Document and build -> Check package now work
fine without crashing...A newer version of the .o and .so objects are now
built and it now works fine.

Thanks
Carl Schwarz

On Wed, Jan 24, 2024 at 10:57 AM Carl Schwarz 
wrote:

> Thanks for your suggestions.  I followed the suggestion in today's message
> (see results below) which all run without issue.
> I tried to isolate the problem more
>
> The issue appears to be with load_dll()
>
> When I try
> > getwd()
> [1] "/Users/cschwarz/Library/CloudStorage/Dropbox/SPAS-R/SPAS"
> > load_dll()
>
> It crashes.
>
>
> I moved the package outside of CloudStorage to see if that is the issue.
> > getwd()
> [1] "/Users/cschwarz/Desktop/SPAS"
> > load_dll()
>
> It crashes.
>
>
> I tried doing a dll_load() where there is NO c++ object, i.e. a random
> directory and it terminates with a sensible error message
> > setwd("/Users/cschwarz/Desktop/BikePics")
> > library(pkgload)
> > load_dll()
> Error in `value[[3L]]()`:
> ! Could not find a root 'DESCRIPTION' file that starts with '^Package' in
> /Users/cschwarz/Desktop/BikePics.
> ℹ Are you in your project directory and does your project have a
> 'DESCRIPTION' file?
> Run `rlang::last_trace()` to see where the error occurred.
>
> I'm following the suggestions on including TMB code in a package at
>
> https://stackoverflow.com/questions/48627069/guidelines-for-including-tmb-c-code-in-an-r-package
> and appear to have all the necessary files
>
> I created my own load_dll() function by copying over the code and adding a
> browser().
> It appears to run fine until the statement library.dynam2(path.lib) where
> it cannot find the function library.dynam2
>
>
> > my_load_dll()
> Called from: my_load_dll()
> Browse[1]> n
> debug at #4: package <- pkg_name(path)
> Browse[2]> n
> debug at #5: env <- ns_env(package)
> Browse[2]> n
> debug at #6: nsInfo <- parse_ns_file(path)
> Browse[2]> n
> debug at #7: dlls <- list()
> Browse[2]> n
> debug at #8: dynLibs <- nsInfo$dynlibs
> Browse[2]> n
> debug at #9: nativeRoutines <- list()
> Browse[2]> n
> debug at #10: for (i in seq_along(dynLibs)) {
> lib <- dynLibs[i]
> dlls[[lib]] <- library.dynam2(path, lib)
> routines <- assignNativeRoutines(dlls[[lib]], lib, env,
> nsInfo$nativeRoutines[[lib]])
> nativeRoutines[[lib]] <- routines
> if (!is.null(names(nsInfo$dynlibs)) &&
> nzchar(names(nsInfo$dynlibs)[i]))
> env[[names(nsInfo$dynlibs)[i]]] <- dlls[[lib]]
> setNamespaceInfo(env, "DLLs", dlls)
> }
> Browse[2]> n
> debug at #11: lib <- dynLibs[i]
> Browse[2]> n
> debug at #12: dlls[[lib]] <- library.dynam2(path, lib)
> Browse[2]> n
> Error in library.dynam2(path, lib) :
>   could not find function "library.dynam2"
>
> I'm unable to find where the library.dynam2() function lies... A google
> search for library.dynam2 doesn't show anything except for a cryptic
> comment in
> https://rdrr.io/cran/pkgload/src/R/load-dll.R
> which says
>
> ## The code below taken directly from base::loadNamespace
>   ## 
> https://github.com/wch/r-source/blob/tags/R-3-3-0/src/library/base/R/namespace.R#L466-L485
>   ## except for the call to library.dynam2, which is a special version of
>   ## library.dynam
>
> This is now beyond my pay grade..
>
> Suggestions?
>
>
> --
>
> From James Lamb 
>
> Using the shell:
>
> R CMD build .
> - success with
>
> * checking for file ‘./DESCRIPTION’ ... OK
>
> * preparing ‘SPAS’:
>
> * checking DESCRIPTION meta-information ... OK
>
> * cleaning src
>
> * installing the package to build vignettes
>
> * creating vignettes ... OK
>
> * cleaning src
>
> * checking for LF line-endings in source and make files and shell scripts
>
> * checking for empty or unneeded directories
>
> * building ‘SPAS_2024.1.31.tar.gz’
>
>
> R CMD INSTALL --with-keep.source ./SPAS_*.tar.gz
> - success. Lots of warning from the C compiler but appears to terminate
> successfully with
> 
>
> installing to /Users/cschwarz/Rlibs/00LOCK-SPAS/00new/SPAS/libs
>
> ** R
>
> ** inst
>
> ** byte-compile and prepare package for lazy loading
>
> ** help
>
> *** installing help indices
>
> ** building package indices
>
> ** installing vignettes
>
> ** testing if installed package can be loaded from temporary location
>
> ** checking absolute paths in shared objects and dynamic libraries
>
> ** testing if installed package can be loaded from final location
>
> ** testing if installed package keeps a record of temporary installation
> path
>
> * DONE (SPAS)
>
>
> # (assuming you use roxygen2)
> Rscript -e "roxygen2::roxygenize(load = 'installed')"
>
>
> - success?, it just returns with no messages
>
> cschwarz@schwarz-iMac-2020 SPAS % Rscript -e "roxygen2::roxygenize(load =
> 'installed')"
>
> cschwarz@schwarz-iMac-2020 SPAS %
>
>
> R CMD check --as-cran ./SPAS_*.tar.gz
>
>