我想将dplyr的编程魔术(新于0.7.0版)用于coalesce两列。在下面,我列出了一些尝试。
df <- data_frame(x = c(1, 2, NA), y = c(2, NA, 3))
# What I want to do:
mutate(df, y = coalesce(x, y))
# Here's the expected output:
#> # A tibble: 3 x 2
#> x y
#> <dbl> <dbl>
#> 1 1 1
#> 2 2 2
#> 3 NA 3
Run Code Online (Sandbox Code Playgroud)
我以为fn1可以用,但是它varname在右侧被视为角色。
fn1 <- function(varname) {
mutate(df, UQ(varname) := coalesce(x, !!varname))
}
fn1("y")
# Error in mutate_impl(.data, dots) : …Run Code Online (Sandbox Code Playgroud) 我想让 Snakemake 为各个规则设置绑定内存限制。根据snakemake 文档,mem_mb参数似乎可行,但该作业使用的内存比我分配的内存多。
这是一个使用几 GB 内存的简单规则。我希望规则在达到内存限制后停止,但它可以毫无问题地完成。
rule:
output:
"a"
threads: 1
resources:
mem_mb = 100
shell:
"""
python3 -c 'import numpy; x=numpy.ones(1_000_000_000)'
touch a
"""
Run Code Online (Sandbox Code Playgroud)
是否可以使此限制绑定?我想要一个可移植的解决方案,适用于 Windows 和 Linux。我在本地使用snakemake,而不是批处理调度程序或容器设置。