我一直试图找到一个解决方案一段时间,但还没有找到任何令人满意的.我编写了很多bash脚本,但有时我想使用R或Python作为脚本的一部分.现在,我最终不得不写两个脚本; 原始bash脚本执行任务的前半部分,而R或Python脚本执行后半部分任务.我在bash脚本中调用R/Python脚本.
我对这个解决方案不满意,因为它将我的程序分成两个文件,这增加了事物不同步的机会,更多的文件要跟踪等等.有没有办法写一个包含整个文件的文本块我的R/Python脚本,然后将bash吐出到一个文件中并将参数传递给它并执行它?有更简单的解决方案吗?这比将简单的单行传递给R/Python更复杂,因为它通常涉及通过几个步骤创建和操作对象.
有没有办法从R计算PDF文件中的页数?如果没有,是否还有另一种与操作系统无关的方法呢?到目前为止,我找到的唯一答案就是这个,它是针对Windows 7的.
我正在尝试在R中编译一些报告,并knitr汇总先前脚本的PDF绘图输出,该脚本自动处理数百个数据集.一些数据集很糟糕,最终打破了绘图功能.由于绘图函数包含在pdf函数中,因此生成一个空的PDF文件,由报告找到并中断pdflatex.尝试修改分析脚本以避免首先生成这些PDF已被证明是困难的,并且是特定于案例的.我真的希望有一些功能可以嵌入到报告中,在包含之前检查PDF> = 1页.我更喜欢基于R的解决方案,尽管bash,LaTeX knitr或pdflatex解决方案也可能就足够了.
编辑:另外,正如我在上一个回答中提到的那样,我试图使用Rpoppler(这里)但是无法让它编译.我在没有管理员权限的CentOS 6环境中使用R版本3.3.0.
我的系统运行的是CentOS 6.我没有管理员权限,所以sudo不可用.我有Python 2.7.3,以及pip和virtualenv.我希望我可以使用它们来设置一个新的虚拟环境来安装和运行Python 3.5或更高版本.
我尝试了这里描述的方法: 在virtualenv中使用Python 3
但得到了这个错误:
$ virtualenv -p python3 venv
The path python3 (from --python=python3) does not exist
Run Code Online (Sandbox Code Playgroud)
我的系统也安装了一个Python 3.4模块,所以我试过了,但是virtualenv似乎没有在那里工作:
$ module load python/3.4.3
$ virtualenv -p python3 venv
-bash: virtualenv: command not found
Run Code Online (Sandbox Code Playgroud)
这似乎有意义,因为virtualenv只为Python 2.7安装:
$ module unload python
$ module load python/2.7
$ which virtualenv
/local/apps/python/2.7.3/bin/virtualenv
Run Code Online (Sandbox Code Playgroud)
因此,下一个逻辑步骤似乎是virtualenv为我的Python 3 安装......但这也不起作用:
$ pip3 install virtualenv
Traceback (most recent call last):
File "/local/apps/python/3.4.3/bin/pip3", line 7, in <module>
from …Run Code Online (Sandbox Code Playgroud) 我在Google上花费了过多的时间,似乎无法弄清楚。
我正在使用R Markdown(此处的文档:http : //rmarkdown.rstudio.com/html_document_format.html)制作HTML文档。
我想更改浮动目录的颜色和其他属性。最好是,我想通过Rmd文件本身中的嵌入式CSS来做到这一点。例如,如果我将其放在Rmd文件中,则可以更改目录中显示的文本的颜色:
---
title: "Untitled"
output:
html_document:
keep_md: true
css: styles.css
toc: true
toc_float: true
number_sections: true
---
<style type="text/css">
#TOC {
color: purple;
}
</style>
Run Code Online (Sandbox Code Playgroud)
输出看起来像这样:
如您所见,目录中的文本现在变为紫色。我如何找出可以通过这种方式更改的其他属性?如何更改突出显示的目录部分的颜色?
我想对这些交互式元素进行更多的自定义,但是我似乎找不到任何有关如何编程它们的文档。能够更改可以使用的Tab药片按钮也很好{.tabset .tabset-pills}。
出于某种原因,optparse此脚本中的用法会中断:
test.R:
#!/usr/bin/env Rscript
library("optparse")
option_list <- list(
make_option(c("-n", "--name"), type="character", default=FALSE,
dest="report_name", help="A different name to use for the file"),
make_option(c("-h", "--height"), type="numeric", default=12,
dest = "plot_height", help="Height for plot [default %default]",
metavar="plot_height"),
make_option(c("-w", "--width"), type="numeric", default=10,
dest = "plot_width", help="Width for plot [default %default]",
metavar="plot_width")
)
opt <- parse_args(OptionParser(option_list=option_list), positional_arguments = TRUE)
print(opt)
report_name <- opt$options$report_name
plot_height <- opt$options$plot_height
plot_width <- opt$options$plot_width
input_dir <- opt$args[1] # input directory
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
$ ./test.R --name "report1" --height 42 …Run Code Online (Sandbox Code Playgroud) 如果我有这样的graphviz dot脚本:
digraph g {
node [style=rounded, shape=box]
subgraph cluster1 {
style="invis"
1 -> 2 -> 3 -> 4 -> 5
}
subgraph cluster2 {
style="invis"
6 -> 7
7 -> 8 -> 11
7 -> 9 -> 11
7 -> 10 -> 11
}
edge[constraint=false];
splines="ortho"
5 -> 6 [weight=0]
}
Run Code Online (Sandbox Code Playgroud)
我得到的输出看起来像这样(我想要的):
但是,如果末尾某些节点中的标签变得太长,则排列将像这样反转:
digraph g {
node [style=rounded, shape=box]
8 [label="very long label"]
9 [label="very long label"]
10 [label="very long label"]
subgraph cluster1 {
style="invis"
1 -> …Run Code Online (Sandbox Code Playgroud) 我有一个类似这里描述的问题,但没有一个我尝试过的解决方案.
给出这样的表:
Date Exercise Category Weight Reps EstMax RepxWeight Note
4/2/16 Deadlift Legs 135 7 166.4685 7x135 easy
4/2/16 Deadlift Legs 135 7 166.4685 7x135 kinda easy
4/2/16 Deadlift Legs 135 7 166.4685 7x135 tired
4/2/16 Bench Press Chest 95 5 110.8175 5x95 hard
4/2/16 Bench Press Chest 135 2 143.991 2x135 not hard
4/9/16 Bench Press Chest 135 2 143.991 2x135 a little hard
4/9/16 Bench Press Chest 135 2 143.991 2x135 super tired
4/18/16 Deadlift Legs …Run Code Online (Sandbox Code Playgroud) 我可以使用此代码生成图表:
档案test.dot:
digraph g {
{rank=same; 1 -> 2 -> 3 -> 4}
{rank=same; 5 -> 6 -> 7 -> 8}
{rank=same; 9 -> 10 -> 11 -> 12}
4 -> 5
8 -> 9
}
Run Code Online (Sandbox Code Playgroud)
dot test.dot -Tpng -o test.png
输出:
但是,我希望节点的排列更像这样:
是否可以制作这样的图形graphviz dot?
r ×5
dot ×2
graphviz ×2
python ×2
bash ×1
css ×1
html ×1
optparse ×1
pandoc ×1
pdf ×1
python-2.7 ×1
r-markdown ×1
virtualenv ×1