因为man/R包的目录中的每个文件都是用包roxygen2自动编写的,我想知道什么会阻止我将整个目录添加到我的文件中.gitignore.
换句话说,为什么GitHub上的所有R包仍然是该man/目录的版本?
library(rlang)
myquo <- quo((Temp - 32) / 1.8)
eval_tidy(myquo, data = as_data_mask(datasets::airquality)) # works
e <- as_env(datasets::airquality, parent = global_env())
eval_tidy(myquo, data = as_data_mask(list(), parent = e)) # error
Run Code Online (Sandbox Code Playgroud)
我期望Temp被发现e.我究竟做错了什么?
PS:我有R版本3.5.0并使用最新的CRAN和GitHub版本的{rlang}进行了测试.
在我的包 {bigstatsr} 中,我在 Solaris 上测试时收到 CRAN 检查的这个错误(请参阅https://www.r-project.org/nosvn/R.check/r-patched-solaris-x86/bigstatsr-00check。 html)。
我设法使用rhub::check_on_solaris(). 默认情况下,创建的文件具有权限,644因为 umask 设置为22.
然后,我尝试将 umask 更改为0,这有效并且我获得了文件权限666(参见https://builder.r-hub.io/status/bigstatsr_1.0.0.tar.gz-a15ab823b9e44e6ca790ee9a143ebadb#L5816)。
如何同时有关于这个文件的权限,我可以得到这个错误与文件的权限666?
我尝试Knit HTML了以下Rmd文件:
---
title: "Untitled"
author: "Florian Privé"
date: "12 septembre 2016"
output: html_document
---
```{r fibCpp, engine='Rcpp'}
#include <Rcpp.h>
// [[Rcpp::export]]
int fibonacci(const int x) {
if (x == 0 || x == 1) return(x);
return (fibonacci(x - 1)) + fibonacci(x - 2);
}
```
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Building shared library for Rcpp code chunk...
Warning message:
l'exécution de la commande 'make -f "C:/PROGRA~1/R/R-33~1.1/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-33~1.1/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="sourceCpp_2.dll" WIN=64 TCLBIN=64 OBJECTS="file110c1d4643e9.o"' renvoie un statut 127
Quitting from lines …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过 RcppArmadillo使用来自犰狳(http://arma.sourceforge.net/docs.html#spsolve)的 SparseLU 求解器:
#define ARMA_USE_SUPERLU
// [Rcpp::depends(RcppArmadillo)]
#include <RcppArmadillo.h>
// [[Rcpp::export]]
arma::vec sp_solver(arma::sp_mat K, arma::vec x) {
arma::superlu_opts opts;
opts.symmetric = true;
arma::vec res;
arma::spsolve(res, K, x, "superlu", opts);
return res;
}
/*** R
library(Matrix)
K <- sparseMatrix(i = c(1, 2, 1), j = c(1, 2, 2), x = c(1, 1, 0.5), symmetric = TRUE)
x <- runif(2)
sp_solver(K, x)
*/
Run Code Online (Sandbox Code Playgroud)
我收到错误undefined reference to 'superlu_free'。我想我缺少一些库链接。知道如何解决这个问题吗?
我在 Windows 10 上。
如果在Rcpp中修改IntegerVector的值:
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
void test(IntegerVector x) {
x[5] = 77;
}
Run Code Online (Sandbox Code Playgroud)
test()在R中运行函数后:
x <- 10:1
test(x)
print(x) # 10 9 8 7 6 77 4 3 2 1
sum(x) # 55
Run Code Online (Sandbox Code Playgroud)
sum函数返回原始数组的值10:1.我怎么解决这个问题?
使用eg时没有问题x <- sample(10L).
基本上,我想sort(sample(n, replace = TRUE))进行n = 1e6,且多次(例如1e4次)。
有什么办法可以更快地在R(cpp)中做到吗?
在我的两台计算机上,我尝试了这段代码:
N <- 10e3
M <- 2000
X <- matrix(rnorm(N * M), N)
system.time(crossprod(X))
Run Code Online (Sandbox Code Playgroud)
第一个是标准笔记本电脑,此操作需要1.7秒.
> sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)
Matrix products: default
BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so
Run Code Online (Sandbox Code Playgroud)
第二个是相当不错的台式电脑,花了17秒.
> sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Linux Mint 18.3
Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.6.0
LAPACK: /usr/lib/lapack/liblapack.so.3.6.0
Run Code Online (Sandbox Code Playgroud)
台式计算机比笔记本电脑更高性能,但这种矩阵计算需要10倍的时间.
问题来自默认的BLAS/LAPACK吗?
我做了一个小包装来重现该问题:
# example package
devtools::install_github("privefl/minipkg")
# example Rmd
rmd <- system.file("extdata", "Matrix.Rmd", package = "minipkg")
writeLines(readLines(rmd)) ## see content
# works fine
rmarkdown::render(
rmd,
"all",
envir = new.env(),
encoding = "UTF-8"
)
# !! does not work !!
minipkg::my_render(rmd)
minipkg::my_render ## see source code
Run Code Online (Sandbox Code Playgroud)
我不明白为什么行为不同以及如何解决此问题。
编辑:我知道我可以使用Matrix::t()。我的问题更多是“为什么在这种特殊情况下而不是在所有其他情况下(例如rmarkdown::render()在包外部调用),为什么需要使用它?”。
Quitting from lines 10-13 (Matrix.Rmd)
Error in t.default(mat) : argument is not a matrix
Run Code Online (Sandbox Code Playgroud)
---
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(Matrix) …Run Code Online (Sandbox Code Playgroud) 我目前正在使用 future 包进行并行化,如下所示:
plan(multisession, gc = TRUE)
standardised_addresses1 <- future_lapply(1:20000, function(x) x*x)
Run Code Online (Sandbox Code Playgroud)
问题是它使用了服务器上的所有 CPU。我想通过设置如下参数来限制使用的CPU数量:workers = 18