r-package

r - data.table and testthat package

谁说我不能喝 提交于 2020-01-11 04:54:29
问题 I am building a package which works with data.table and which should be tested using package testthat. While the code works fine when calling from the command line, I run into issues when calling from a test case. It seems that the [] function from the base package, i.e. the function for data.frames is used when running the tests. I have created a minimum example which can be found here: https://github.com/utalo/test_datatable_testthat The package contains a single function: test <- function(

R: How to run some code on load of package?

只谈情不闲聊 提交于 2020-01-09 09:22:42
问题 I am learning to build a package for R. Now to set it up I need to run some code when the package is being loaded via require(myPackage) . I read the documentation on help(".onLoad") that just made me really confused as there is no example. How do I actually use .onLoad ? Can someone please show me a simple example? For example I know export(myfun) in the NAMESPACE file will export myfun for use, what is the code that I need to run say rnorm(10) at package load? 回答1: There is usually a

“object not found” during package build/install

穿精又带淫゛_ 提交于 2020-01-06 06:04:15
问题 I'm at a loss to debug building/installing a package. Building a package "MyProjekt" through > devtools::build("MyProjekt") works fine, even though > devtools::document() Updating MyProjekt documentation Loading MyProjekt Error: object 'rank' not found whilst loading namespace 'MyProjekt' fails. Attempting to install the built (pure R) package > install.packages(pkgs="./MyProjekt.tar.gz") ... Error: package or namespace load failed for 'MyProjekt': object 'rank' not found whilst loading

“object not found” during package build/install

╄→尐↘猪︶ㄣ 提交于 2020-01-06 06:03:05
问题 I'm at a loss to debug building/installing a package. Building a package "MyProjekt" through > devtools::build("MyProjekt") works fine, even though > devtools::document() Updating MyProjekt documentation Loading MyProjekt Error: object 'rank' not found whilst loading namespace 'MyProjekt' fails. Attempting to install the built (pure R) package > install.packages(pkgs="./MyProjekt.tar.gz") ... Error: package or namespace load failed for 'MyProjekt': object 'rank' not found whilst loading

Create R data with a dynamic variable name from function for package?

岁酱吖の 提交于 2020-01-05 05:47:27
问题 I am working on a function which is part of a package. This package contains a template for a new package, and a function which creates R data for the new package which has to have a dynamic name provided to this function. At the moment I am doing the following: makedata <- function(schemeName, data) { rdsFile <- paste0(schemeName, ".rds") varName <- paste0(schemeName) saveRDS( data, file = file.path( ".", "data", rdsFile ) ) cat( paste0(varName, " <- readRDS(\"./", rdsFile, "\")"), file =

How to add external data file into developing R package?

天大地大妈咪最大 提交于 2020-01-02 04:08:08
问题 I am building my R packages in Rstudio, I ran into some unexpected problem when I tired to create package' vignette. when I hit build/load panel in Rstudio, I got vignette error, while package's documentation was created. To possibly solve vignette error I got, I have to add external data to my packages, use this data to compile package vignette accordingly. I used devtools::install() command to install my packages, but inst/ directory is not created. extdata must be located in inst directory

Package Relative Paths in R

半城伤御伤魂 提交于 2020-01-01 02:27:12
问题 I've written a few functions for a package that use relative paths like: "./data/foobar.rds" Here's an example function: foo <- function(x) { x <- readRDS("./data/bar.rds") return(x) } Now, if I were to be working in the development path of the package, this works as I expect. But when I load the package, this path uses the current working directory rather than the relative path of the package. How does one set it up such that the path for functions within a package maintain their within the

Using inst/extdata with vignette during package checking R 2.14.0

夙愿已清 提交于 2019-12-30 07:08:12
问题 I have a package which contains a csv file which I put in inst/extdata per R-exts. This file is needed for the vignette. If I Sweave the vignette directly, all works well. When I run R --vanilla CMD check however, the check process can't find the file. I know it has been moved into an .Rcheck directory during checking and this is probably part of the problem. But I don't know how to set it up so both direct Sweave and vignette building/checking works. The vignette contains a line like this:

How to modify unexported object in a package

强颜欢笑 提交于 2019-12-29 01:37:30
问题 My package (let's call it A) depends on another package B. I need to modify a function f in B that has a bug that is causing my package to fail. The problem is that f is an unexported function. If f was exported, I could use the technique described in this post to R-help: The few times I want to patch a function like this, I use: unlockBinding(name, env); assignInNamespace(name, value, ns=pkgName, envir=env); assign(name, value, envir=env); lockBinding(name, env); But because f is unexported,

Rcpp wrapper for the .C interface

徘徊边缘 提交于 2019-12-24 12:21:53
问题 I help to maintain the R package iRF. As you can see, it have been using Rcpp to call some C functions via the .C interface since its last release in 2017. When I clone that repo and try to install it on my computer (running macOS Mojave) with the latest version of R and Rcpp, it installs successfully. However, any modification to the src/ directory would change some MD5 hash and trigger an Rcpp::compileAttributes . Unfortunately, the recompiled attributes don't work with the legacy .C