drake readd 函数不适用于绘图
drake readd function not working for plots
我正在尝试解决为什么 Drake
图没有显示 readd()
- 管道的其余部分似乎已经工作了。
不确定这是 minfi::densityPlot
还是其他原因造成的;我的想法是后来的,因为它也不适用于基于 R.
的 barplot
函数
在 RMarkdown 报告中,我有 readd(dplot1)
等 块,但输出是 NULL
这是我的 R/setup.R
文件中的代码:
library(drake)
library(tidyverse)
library(magrittr)
library(minfi)
library(DNAmArray)
library(methylumi)
library(RColorBrewer)
library(minfiData)
pkgconfig::set_config("drake::strings_in_dots" = "literals") # New file API
# Your custom code is a bunch of functions.
make_beta <- function(rgSet){
rgSet_betas = minfi::getBeta(rgSet)
}
make_filter <- function(rgSet){
rgSet_filtered = DNAmArray::probeFiltering(rgSet)
}
这是我的 R/plan.R
文件:
# The workflow plan data frame outlines what you are going to do
plan <- drake_plan(
baseDir = system.file("extdata", package = "minfiData"),
targets = read.metharray.sheet(baseDir),
rgSet = read.metharray.exp(targets = targets),
mSetSq = preprocessQuantile(rgSet),
detP = detectionP(rgSet),
dplot1 = densityPlot(rgSet, sampGroups=targets$Sample_Group,main="Raw", legend=FALSE),
dplot2 = densityPlot (getBeta (mSetSq), sampGroups=targets$Sample_Group, main="Normalized", legend=FALSE),
pal = RColorBrewer::brewer.pal (8,"Dark2"),
dplot3 = barplot (colMeans (detP[,1:6]), col=pal[ factor (targets$Sample_Group[1:6])], las=2, cex.names=0.8, ylab="Mean detection p-values"),
report = rmarkdown::render(
knitr_in("report.Rmd"),
output_file = file_out("report.html"),
quiet = TRUE
)
)
使用make(plan)
后一切看起来运行都很顺利:
config <- drake_config(plan)
vis_drake_graph(config)
我可以使用 loadd()
加载这些绘图之一所需的对象,然后制作绘图,如下所示:
loadd(rgSet)
loadd(targets)
densityPlot(rgSet, sampGroups=targets$Sample_Group,main="Raw", legend=FALSE)
但是 readd()
命令不起作用?
.html
中 dplot3 的输出看起来很奇怪...
幸运的是,这是预期的行为。 drake
目标是命令的 return 值,因此 dplot3
的值应该是 barplot()
的 return 值。 barplot()
的return值其实不是剧情。帮助文件 (?barplot
) 的 "Value" 部分解释了 return 值。
A numeric vector (or matrix, when beside = TRUE), say mp, giving the coordinates of all the bar midpoints drawn, useful for adding to the graph.
If beside is true, use colMeans(mp) for the midpoints of each group of bars, see example.
所以这是怎么回事?与大多数基本图形函数一样,barplot()
中的绘图实际上是一个副作用。 barplot()
将绘图发送到图形设备,然后 return 将其他内容发送给用户。
你考虑过ggplot2
吗? ggplot()
的return值其实是一个plot对象,比较直观。如果您想坚持使用基本图形,也许您可以将绘图保存到输出文件中。
plan <- drake_plan(
...,
dplot3 = {
pdf(file_out("dplot3.pdf"))
barplot(...)
dev.off()
}
)
我正在尝试解决为什么 Drake
图没有显示 readd()
- 管道的其余部分似乎已经工作了。
不确定这是 minfi::densityPlot
还是其他原因造成的;我的想法是后来的,因为它也不适用于基于 R.
barplot
函数
在 RMarkdown 报告中,我有 readd(dplot1)
等 块,但输出是 NULL
这是我的 R/setup.R
文件中的代码:
library(drake)
library(tidyverse)
library(magrittr)
library(minfi)
library(DNAmArray)
library(methylumi)
library(RColorBrewer)
library(minfiData)
pkgconfig::set_config("drake::strings_in_dots" = "literals") # New file API
# Your custom code is a bunch of functions.
make_beta <- function(rgSet){
rgSet_betas = minfi::getBeta(rgSet)
}
make_filter <- function(rgSet){
rgSet_filtered = DNAmArray::probeFiltering(rgSet)
}
这是我的 R/plan.R
文件:
# The workflow plan data frame outlines what you are going to do
plan <- drake_plan(
baseDir = system.file("extdata", package = "minfiData"),
targets = read.metharray.sheet(baseDir),
rgSet = read.metharray.exp(targets = targets),
mSetSq = preprocessQuantile(rgSet),
detP = detectionP(rgSet),
dplot1 = densityPlot(rgSet, sampGroups=targets$Sample_Group,main="Raw", legend=FALSE),
dplot2 = densityPlot (getBeta (mSetSq), sampGroups=targets$Sample_Group, main="Normalized", legend=FALSE),
pal = RColorBrewer::brewer.pal (8,"Dark2"),
dplot3 = barplot (colMeans (detP[,1:6]), col=pal[ factor (targets$Sample_Group[1:6])], las=2, cex.names=0.8, ylab="Mean detection p-values"),
report = rmarkdown::render(
knitr_in("report.Rmd"),
output_file = file_out("report.html"),
quiet = TRUE
)
)
使用make(plan)
后一切看起来运行都很顺利:
config <- drake_config(plan)
vis_drake_graph(config)
我可以使用 loadd()
加载这些绘图之一所需的对象,然后制作绘图,如下所示:
loadd(rgSet)
loadd(targets)
densityPlot(rgSet, sampGroups=targets$Sample_Group,main="Raw", legend=FALSE)
但是 readd()
命令不起作用?
.html
中 dplot3 的输出看起来很奇怪...
幸运的是,这是预期的行为。 drake
目标是命令的 return 值,因此 dplot3
的值应该是 barplot()
的 return 值。 barplot()
的return值其实不是剧情。帮助文件 (?barplot
) 的 "Value" 部分解释了 return 值。
A numeric vector (or matrix, when beside = TRUE), say mp, giving the coordinates of all the bar midpoints drawn, useful for adding to the graph.
If beside is true, use colMeans(mp) for the midpoints of each group of bars, see example.
所以这是怎么回事?与大多数基本图形函数一样,barplot()
中的绘图实际上是一个副作用。 barplot()
将绘图发送到图形设备,然后 return 将其他内容发送给用户。
你考虑过ggplot2
吗? ggplot()
的return值其实是一个plot对象,比较直观。如果您想坚持使用基本图形,也许您可以将绘图保存到输出文件中。
plan <- drake_plan(
...,
dplot3 = {
pdf(file_out("dplot3.pdf"))
barplot(...)
dev.off()
}
)