在igraphR包中,是否有一个subcomponent()可以处理多个源顶点的有效实现和/或BFS?
在drake[R包装机型用户的工作流程是相互依存的对象和文件的DAG.DAG应该只包含用户的目标及其上游依赖项,因此drake用于igraph::subcomponent()消除多余的顶点.这种方法效率很低,因为v参数必须是单个顶点,因此drake最终会为用户想要构建的每个目标执行新的BFS.
drake现在使用一种不同的方法,最终依赖于顺序调用adjacent_vertices().这种方法很笨重,但速度提升实际上非常好.仍然坚持更优雅和精致的东西.
如何告诉R Markdown/knitr尊重蜡笔颜色代码?我有以下R Markdown报告.
---
title: "MWE"
author: "Will Landau"
date: "11/20/2017"
output: html_document
---
```{r color}
message(crayon::make_style("green")("My green message."))
```
Run Code Online (Sandbox Code Playgroud)
当我编织并渲染它时,我看到了输出
## My green message.
Run Code Online (Sandbox Code Playgroud)
但文字颜色不是绿色.
是否可以锁定全局环境并且仍然允许.Random.seed设置或删除全局环境?在lockEnvironment()我的用例中,的默认行为过于激进。
lockEnvironment(globalenv())
rnorm(10)
#> Error in rnorm(10) : cannot add bindings to a locked environment
rm(.Random.seed)
#> Error in rm(.Random.seed) :
#> cannot remove bindings from a locked environment
Run Code Online (Sandbox Code Playgroud)
drake 7.0.0版将具有新的保护措施,以保护可重复性。
plan <- drake_plan(
x = {
data(mtcars)
mtcars$mpg
},
y = mean(x)
)
plan
#> # A tibble: 2 x 2
#> target command
#> <chr> <expr>
#> 1 x { data(mtcars) mtcars$mpg }
#> 2 y mean(x)
make(plan)
#> target x
#> fail …Run Code Online (Sandbox Code Playgroud) 我正在用S4类构建一个R包,我在使用该new函数时遇到了麻烦.我有一个叫做的课Configs
setClass("Configs",
slots = list(
burnin = "numeric",
chains = "numeric",
features = "numeric",
iterations = "numeric",
mphtol = "numeric",
samples = "numeric",
seed = "numeric",
thin = "numeric",
verbose = "numeric"
),
prototype = list(
burnin = 0,
chains = 2,
features = 5,
iterations = 5,
mphtol = 1e-4,
samples = 3,
seed = sample(1e6, 1),
thin = 0,
verbose = 0
)
)
Run Code Online (Sandbox Code Playgroud)
当我将这部分加载到我的全局环境中时,我可以Configs使用不同于默认值的插槽创建一个新对象.
> new("Configs", features = 1000)
An object of …Run Code Online (Sandbox Code Playgroud) 当我尝试在 Shiny 应用程序中编辑 rhandsontable 的条目时,下拉菜单被缩短了。有没有办法让它们像rhandsontable 教程中的日期选择器一样完全扩展?这是应用程序。
library(rhandsontable)
library(shiny)
ui = fluidPage(rHandsontableOutput("data"))
server = function(input,output) {
df = data.frame(x = factor(letters[1:3], levels = letters))
values = reactiveValues(data = df)
observe({
req(input$data)
values$data = hot_to_r(input$data)
})
output$data = renderRHandsontable({
rhandsontable(values$data)
})
}
shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud) 我维护一个 R 包,需要单独检查大量小文件的存在。重复调用以file.exists()产生明显的缓慢(此处为基准测试结果)。不幸的是,情境限制阻止我file.exists()以矢量化方式对整批文件调用一次,我相信这会快得多。有没有更快的方法来检查单个文件是否存在?也许在C?这种方式在我的系统上似乎并没有更快(产生这些基准的同一个):
library(inline)
library(microbenchmark)
body <- "
FILE *fp = fopen(CHAR(STRING_ELT(r_path, 0)), \"r\");
SEXP result = PROTECT(allocVector(INTSXP, 1));
INTEGER(result)[0] = fp == NULL? 0 : 1;
UNPROTECT(1);
return result;
"
file_exists_c <- cfunction(sig = signature(r_path = "character"), body = body)
tmp <- tempfile()
microbenchmark(
c = file_exists_c(tmp),
r = file.exists(tmp)
)
#> Unit: microseconds
#> expr min lq mean median uq max neval
#> c 4.912 5.0230 5.42443 5.0605 5.1240 25.264 …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种巧妙的方法来以编程方式获取包的Imports:和Depends:包。诀窍在于,无论包是否存在,该方法都应该有效
devtools::load_all(),或所需功能:
package_deps("dplyr")
## [1] "assertthat" "bindrcpp" "glue" "magrittr" "methods" "pkgconfig"
## [7] "rlang" "R6" "Rcpp" "tibble" "utils"
Run Code Online (Sandbox Code Playgroud)
请注意,版本号已全部被删除。
我写这篇文章是因为它似乎应该已经存在。(毕竟,install.packages()需要类似的功能。)我宁愿不必自己管理所有特殊情况。
对于 R 包,是否存在关于弃用过时函数后应保留该函数多长时间的指南?降级到废止怎么办?去念?
从提交作业的本地计算机(例如通过 AWS CLI)反向隧道进入 AWS Batch 阵列作业究竟需要什么?与典型的反向隧道方案不同,这里的远程节点不与本地计算机共享本地网络。动机:https : //github.com/mschubert/clustermq/issues/208。相关:ssh 进入 AWS Batch 作业。
是的,我知道 SSH 在纯 EC2 中更容易,但 Batch 更可取,因为它支持任意 Docker 镜像、轻松的作业监控和自动现货定价。
我有一个CUDA程序,它使用thrust :: reduce来并行化和:例如,
thrust::device_ptr<double> tmp(aux);
double my_sum = thrust::reduce(tmp, tmp + G);
Run Code Online (Sandbox Code Playgroud)
在设备上double* aux指向G连续的双打.我需要将整个并行化程序的运行时间与没有并行计算的版本进行比较.有没有办法thrust::reduce在设备上只使用一个线程运行?全局转换将是最方便的选择.
我正在构建CUDA加速的R包,我想调试cuda-memcheck.所以在这个最小的例子中(在deliberate_memory_leakGitHub分支中),我someCUDAcode.c通过注释掉必要的调用来创建内存泄漏cudaFree.然后,我看是否cuda-memcheck可以找到泄漏.
$ cuda-memcheck --leak-check full Rscript -e 'library(rcppcuda); hello()'
========= CUDA-MEMCHECK
An object of class "MyClass"
Slot "x":
[1] 1 2 3 4 5 6 7 8 9 10
Slot "y":
[1] 1 2 3 4 5 6 7 8 9 10
[1] "Object changed."
An object of class "MyClass"
Slot "x":
[1] 500 2 3 4 5 6 7 8 9 10
Slot "y":
[1] 1 1000 …Run Code Online (Sandbox Code Playgroud) r ×9
cuda ×2
r-package ×2
ropensci ×2
amazon-ec2 ×1
aws-batch ×1
c ×1
deprecated ×1
igraph ×1
knitr ×1
memory-leaks ×1
new-operator ×1
r-markdown ×1
s4 ×1
shiny ×1
slots ×1
ssh-tunnel ×1
thrust ×1
valgrind ×1