可能重复:
Bash:如何为多行命令添加行注释
我想做这样的事情
sudo apt-get install \
#a very long description
#of the package
#that spans multiple lines
pkg1 \ #maybe I want an inline comment also
#another description that
#spans multiple lines
pkg2
Run Code Online (Sandbox Code Playgroud)
请注意,我不仅对apt-get命令感兴趣.
我想我正在寻找rbind.fill(在Hadley的plyr包装中)的类比cbind.我看了,但没有cbind.fill.
我想做的是以下内容:
#set these just for this example
one_option <- TRUE
diff_option <- TRUE
return_df <- data.frame()
if (one_option) {
#do a bunch of calculations, produce a data.frame, for simplicity the following small_df
small_df <- data.frame(a=1, b=2)
return_df <- cbind(return_df,small_df)
}
if (diff_option) {
#do a bunch of calculations, produce a data.frame, for simplicity the following small2_df
small2_df <- data.frame(l="hi there", m=44)
return_df <- cbind(return_df,small2_df)
}
return_df
Run Code Online (Sandbox Code Playgroud)
可以理解,这会产生错误:
Error in data.frame(..., check.names …Run Code Online (Sandbox Code Playgroud) 我在文件中有以下内容(我将其称为"myfile"):
[{
"id": 123,
"name": "John",
"aux": [{
"abc": "random",
"def": "I want this"
}],
"blah": 23.11
}]
Run Code Online (Sandbox Code Playgroud)
我可以解析它没有[和]如下:
$ cat myfile | jq -r '.aux[] | .def'
I want this
$
Run Code Online (Sandbox Code Playgroud)
但随着[和]我得到:
$ cat myfile | jq -r '.aux[] | .def'
jq: error: Cannot index array with string
Run Code Online (Sandbox Code Playgroud)
我该如何处理[和]使用jq?(我确信我可以使用不同的工具解析它们,但我想学习正确使用jq.
我在这里使用这个例子进行讨论: ggplot map with l
library(rgdal)
library(ggplot2)
library(maptools)
# Data from http://thematicmapping.org/downloads/world_borders.php.
# Direct link: http://thematicmapping.org/downloads/TM_WORLD_BORDERS_SIMPL-0.3.zip
# Unpack and put the files in a dir 'data'
gpclibPermit()
world.map <- readOGR(dsn="data", layer="TM_WORLD_BORDERS_SIMPL-0.3")
world.ggmap <- fortify(world.map, region = "NAME")
n <- length(unique(world.ggmap$id))
df <- data.frame(id = unique(world.ggmap$id),
growth = 4*runif(n),
category = factor(sample(1:5, n, replace=T)))
## noise
df[c(sample(1:100,40)),c("growth", "category")] <- NA
ggplot(df, aes(map_id = id)) +
geom_map(aes(fill = growth, color = category), map =world.ggmap) +
expand_limits(x = world.ggmap$long, y = world.ggmap$lat) + …Run Code Online (Sandbox Code Playgroud) 我无法绕过这个.为什么将/dev/null用作if语句的输入?以下是什么用途< /dev/null?
if ( $PROG --version ) < /dev/null > /dev/null 2>&1; then
$PROG
else
echo "failed"
exit 1
fi
Run Code Online (Sandbox Code Playgroud)
我(觉得)我明白,> /dev/null 2>&1只是用来抑制来自任何输出stdout和stderr.
havebash中是关键字吗?或者bash完成脚本使用的语言不是bash?
have gcc &&
_gcc()
{
Run Code Online (Sandbox Code Playgroud)
是很常见.看到:grep "have .* &&" /etc/bash_completion.d/*
我找不到关于我看过的bash完成教程的任何信息,我找不到任何信息man bash.谷歌"有"也很难.我在哪里可以找到相关文档?
我猜这与确保gcc存在于PATH?有关.
编辑:是的./etc/bash_completion包含:
have()
{
unset -v have
# Completions for system administrator commands are installed as well in
# case completion is attempted via `sudo command ...'.
PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin type $1 &>/dev/null &&
have="yes"
}
Run Code Online (Sandbox Code Playgroud) 假设我有两个矩阵,每个矩阵有两列和不同的行数.我想检查并查看另一个矩阵中哪一对矩阵.如果这些是一维的,我通常只是a %in% x为了得到我的结果.match似乎只对矢量有效.
> a
[,1] [,2]
[1,] 1 2
[2,] 4 9
[3,] 1 6
[4,] 7 7
> x
[,1] [,2]
[1,] 1 6
[2,] 2 7
[3,] 3 8
[4,] 4 9
[5,] 5 10
Run Code Online (Sandbox Code Playgroud)
我希望结果如此c(FALSE,TRUE,TRUE,FALSE).
我想逐步完成,使用debug()或者trace(),一个未导出的函数.例如,我如何为从函数调用vcov.polr的包执行MASS此操作polr.polr导出,但vcov.polr不是.
也就是说,当我运行时polr,我希望调试浏览器在代码进入后启动vcov.polr.
我看到很多关于如何自定义图例的问题,但我甚至无法获得自定义的图例.我想有一个传说解释黑线是二次的,绿线是立方的.
library(ggplot2)
myfun1 <- function(x) x^2
myfun2 <- function(x) x^3
myplot <- ggplot(data = data.frame(x = 1:5, y= 1:5), aes(x=x, y=y)) +
stat_function(fun = myfun1, color="green") +
stat_function(fun = myfun2, color="black")
Run Code Online (Sandbox Code Playgroud) 我想要两个独立的情节.我在一个投影仪演示的不同帧中使用它们,我将向另一个添加一行(最终,不在下面的示例中).因此,我不希望演示文稿从一张幻灯片"跳过"("跳转"?)到下一张幻灯片.我希望它看起来像是自然添加的线.我认为以下代码显示了问题.这是微妙的,但不是如何第二个图的绘图区域略大于第一个图.这是因为y轴标签.
library(ggplot2)
dfr1 <- data.frame(
time = 1:10,
value = runif(10)
)
dfr2 <- data.frame(
time = 1:10,
value = runif(10, 1000, 1001)
)
p1 <- ggplot(dfr1, aes(time, value)) + geom_line() + scale_y_continuous(breaks = NULL) + scale_x_continuous(breaks = NULL) + ylab(expression(hat(z)==hat(gamma)[1]*time+hat(gamma)[4]*time^2))
print(p1)
dev.new()
p2 <- ggplot(dfr2, aes(time, value)) + geom_line() + scale_y_continuous(breaks = NULL) + scale_x_continuous(breaks = NULL) + ylab(".")
print(p2)
Run Code Online (Sandbox Code Playgroud)
我宁愿没有一个hackish解决方案,如手动设置轴标签的大小或在x轴上添加空格(参见下面的一个参考),因为我将在几个设置中使用此技术,标签可以在任何设置更改时间(我喜欢再现性,所以想要一个灵活的解决方案).
我搜索了很多,发现了以下内容:
https://groups.google.com/forum/#!topic/ggplot2/2MNoYtX8EEY
如何在不改变绘图宽度的情况下在R中使用ggplot2添加可变大小的y轴标签?
它们对我不起作用,主要是因为我需要单独的图,因此不需要像上面的一些解决方案那样在一个组合图上对齐它们.