I've just pushed a package on Github, which I regularly document, test and install on my machine with the following R commands:
library(devtools)
library(testthat)
setwd("bimark")
document() # cheers to roxygen2!
use_testthat() # cheers to testthat!
setwd("..")
install("bimark", build_vignettes=TRUE) # cheers to R-markdown!
library(bimark)
test_package("bimark")
run_examples("bimark")
However, installing it from github with:
install_github("iago-lito/bimark")
does not work since
ERROR: a 'NAMESPACE' file is required
The reason why I do not version my NAMESPACE file is that it is automatically generated by devtools::document().
How can I make the full doc-test-installation easy for my users without versionning non-source files such as NAMESPACE?
NAMESPACE is autogenerated only if devtools::document() and roxygen2 is used. Otherwise, you create it by hand. Therefore, I think they consider it as a source file which needs to be versioned.
Related
The whole issue is stated in the title.
Try it by yourself:
create a project w/ {renv},
install a package, and add any function call from that package in the project .Rprofile,
snapshot it to renv.lock,
put a GitHub action (e.g., using {usethis} wrapper),
push it on GitHub.
You can find a ready-to-inspect errored reprex project here.
I have tried to:
install the package from within the project .Rprofile
before or after sourcing renv/activate.R
using renv::install or utils::install.packages (setting an option for the CRAN repo)
using utils::install.packages, sourcing renv/activate.R, and next using renv::install
None of my options/combinations worked, and the GH-action still return the error: "Error: Error in loadNamespace(x) : there is no package called ‘<package-name>’".
Do you have some hints for trying to solve this issue? Is that an issue from {renv} or GH-action?
Thank you!
Corrado.
I'm working in a package (and I'll include more later), and I'm doing a lot of changes and using it, and I'm looking for a method to can load the library without compile it, the lib is written in R.
I think the next structure:
Code
libs/
test_pkg1/
test_pkg2/
more code.R
Where the test_pkg are the dirs with the packages, they are already in the pkg format for R, the wd is set inside "Code", and then add "libs" to the library path in R, but R does not detect it.
I'm trying to use the libs in this both ways:
test_pkg1::func()
test_pkg2::func()
library(test_pkg1)
library(test_pkg2)
for the library, I can use devtools::load_all(path), and works great, but I don't want to mix the env with other funcs, so I need the other way too.
I'm not trying to use both at the same time, but I need both, the most important for this is the :: method.
I tested the libPath from here:
Change R default library path using .libPaths in Rprofile.site fails to work
But I can't do it works...., using that I get the next result:
.libPaths( c( .libPaths(), "./libs") )
test_pkg1::func()
Error in namespaceExport(ns, exports) : undefined exports: func()
Although: Warning message:
In loadNamespace(name) : package ‘test_pkg1’ has no 'package.rds' in Meta/
Note, If I install the package, all works fine, the NAMESPACE file, contains the export functions, in any case, any error there and I should not be able to install and use the libs.
Thx.
Tests from comments:
Try library(pkg, lib.loc)
library("test_pkg1", lib.loc="./libs", verbose=TRUE)
Error in library("test_pkg1", lib.loc = "./libs", verbose = TRUE) :
‘test_pkg1’ is not a valid installed package
Notice, the message is not, there is no package called, the package is detected, but seems, how is not built, I can't load it from library. I try build the package, but don't works either.
Try devtools::dev_mode(on = NULL, path = "libs")
Sadly, this method seems to have the same behavior as the .libsPath method.
I have an R package, created by someone else that I have been made a collaborator on, that I want to work on and develop. I've already cloned the repository to my local computer through the Create Project > Clone from GitHub route in RStudio, and since then I've been editing the scripts, but not working with it as a package. As in, I had been adding functions and working on a Shiny interface, but not following any R package development rules (loading packages directly into the .R files, not updating the NAMESPACE, using roxygen2 conventions, etc.).
Everything I've read mentions devtools::install_github, but I don't want to install and use it, I want to edit it like I've been doing. I also want it to still be connected to Git (so I can continue to commit and pull from the remote server, once my collaborators make edits). I've tried devtools::load_all() and devtools::document(), but it gives me this warning:
Error in FUN(X[[i]], ...) :
bad restore file magic number (file may be corrupted) -- no data loaded
In addition: Warning messages:
1: In readChar(con, 5L, useBytes = TRUE) :
truncating string with embedded nuls
2: file ‘file_example.rda’ has magic number 'X'
Use of save versions prior to 2 is deprecated
Do I need to delete my local copy and do something different to work with it as a package so that the functionality of roxygen2 and the NAMESPACE documentation will work correctly? Or is there an obvious reason for this error/something I'm missing about how to work with it as a package, how it is currently?
Thanks!
It looks like file_example.rda is corrupt
Can you just load it in R and check what it contains?
You could try:
tools::resaveRdaFiles( 'file_example.rda', compress='xz' )
And see if that saves it in a way that is acceptable?
I am trying to use the library libspatialite to extend sqlite on a NetBSD platform. I've taken the first step of creating a package for libspatialite in pkgsrc (libspatialite-4.1.1). The package appears to work; pkg_info says it's installed and I've verified that the files from PLIST (in code chunk below) have been installed in /usr/pkg/. However, when I try to install the package I built for spatialite-tools, configure says that libspatialite isn't installed. Also I can't figure out how to load the library in sqlite3 with load_extenstion(X,Y); what is the library file referred to in the documentation?
pkgsrc/databases/libsqlite/PLIST:
#comment $NetBSD$
include/spatialite.h
include/spatialite/debug.h
include/spatialite/gaiaaux.h
include/spatialite/gaiaexif.h
include/spatialite/gaiageo.h
include/spatialite/geopackage.h
include/spatialite/gg_advanced.h
include/spatialite/gg_const.h
include/spatialite/gg_core.h
include/spatialite/gg_dxf.h
include/spatialite/gg_dynamic.h
include/spatialite/gg_formats.h
include/spatialite/gg_mbr.h
include/spatialite/gg_structs.h
include/spatialite/gg_wfs.h
include/spatialite/gg_xml.h
include/spatialite/spatialite.h
include/spatialite/sqlite.h
lib/libspatialite.la
lib/pkgconfig/spatialite.pc
Do you have a buildlink3.mk file in the libspatialite package?
If not:
In order to avoid a package building against implicit dependencies pkgsrc only makes libraries which have been explicitly listed visible to the building package.
This stop the issue of a package picking up an optional dependency which just happens to be installed, then building a binary package which uses that library but does not have it listed in the package metadata. The resultant binary package will work fine on that system... until the optional dependency is removed, and will fail on any other system without that hidden dependency.
Anyway... buildlink3.mk files are used in pkgsrc to make the necessary files visible during a build. A libspatialite buildlink3.mk might look like the below (adjust 1.0 to the current lib version)
# $NetBSD$
BUILDLINK_TREE+= libspatialite
.if !defined(LIBSPATIALITE_BUILDLINK3_MK)
LIBSPATIALITE_BUILDLINK3_MK:=
BUILDLINK_API_DEPENDS.libspatialite+=libspatialite>=1.0
BUILDLINK_PKGSRCDIR.libspatialite?= ../../devel/libspatialite
BUILDLINK_LIBDIRS.libspatialite+= lib/spatialite
BUILDLINK_RPATHDIRS.libspatialite+= lib/spatialite
BUILDLINK_INCDIRS.libspatialite+= include/spatialite
.endif # LIBSPATIALITE_BUILDLINK3_MK
BUILDLINK_TREE+= -libspatialite
Then in the depending package add something like:
.include "../../devel/libspatialite/buildlink3.mk"
I've written a OpenCPU app package and have successfully tested it in single server mode. The server is setup and it can find the app no problem.
But it's erroring out on some of the ocpu calls with the following (from Chrome JS console):
POST http://mydomain/ocpu/library/userengagementdashboard/R/metricsList 400 (Bad Request) jquery-1.10.2.min.js:6
OpenCPU error HTTP 400
package or namespace load failed for 'userengagementdashboard'
In call:
NULL
Didn't get these errors in the single user server mode.
If I check on http://mydomain/ocpu/library/userengagementdashboard/NAMESPACE I get:
export(aggregatePlot)
export(clusterFun)
export(facetPlot)
export(facetsList)
export(getDataAll)
export(getDataFacet)
export(getDataTime)
export(getDataTimeFacet)
export(mergeClusters)
export(metricsList)
export(timeFacetPlot)
export(timePlot)
import(RDruid)
import(ggplot2)
import(lubridate)
import(parallel)
import(plyr)
import(reshape)
Is there a problem with my imports maybe?
UPDATE:
Solved this thanks to Jeroen's suggestion that I perhaps didn't have all the dependencies.
First I looked at the dependencies under http://mydomain/ocpu/library/ and installed any missing packages to the correct library location.
Then some of the imports and dependencies of these dependent packages had not been installed so I installed their dependencies as well. Problem solved!
Your package probably fails to load because some dependencies are not installed. This problem usually appears if the NAMESPACE file imports dependencies, which are not declared in the DESCRIPTION file. So if your NAMESPACE contains:
import(RDruid)
import(ggplot2)
import(lubridate)
import(parallel)
import(plyr)
import(reshape)
than your DESCRIPTION needs to contain a line:
Imports: Druid, ggplot2, lubridate, parallel, plyr, reshape
The R package manager looks at the DESCRIPTION to install dependencies when installing your package.