使用R,我想生成多个字符串,例如:
"modelCheck("var1_d.bug")"
"modelCheck("var2_d.bug")"
...
"modelCheck("var10_d.bug")"
Run Code Online (Sandbox Code Playgroud)
我通常会使用for循环和粘贴(如果我不必担心双引号),如下所示:
for(i in 1:10){
str<-paste("modelCheck(var",i,"_d.bug)",sep="")
print(str)
}
Run Code Online (Sandbox Code Playgroud)
但是,我需要在字符串中包含双引号,因此请求帮助?
我试图R CMD check --as-cran [my package]在我的Windows命令提示符下检查我已经构建的包(使用晕影).一切顺利,直到我收到消息,
WARNING 'qpdf' is needed for checks on size reduction of PDFs
Run Code Online (Sandbox Code Playgroud)
我已经下载了qpdf,将解压缩的文件夹放在我的程序文件目录中,并将bin文件夹添加到PATH中.
不太确定我还需要做什么?我觉得我没有正确安装qpdf或者我需要自己构建这个程序?我已经阅读了qpdf的自述文件和手册,它们似乎更多地针对unix用户(我没有经验...我是你的标准/常规Windows用户,除了统计语言之外几乎没有编程经验).我尝试使用cgywin构建qpdf,但最终无法安装zlib和prec.有小费吗?
我无法想出一种downloadButton与a 底对齐的方法selectizeInput,即

library(shiny)
runApp(list(
ui = shinyUI(fluidPage(
fluidRow(align="bottom",
column(12, align="bottom",
h4("Download Options:"),
fluidRow(align="bottom",
column(6, selectizeInput("plot_dl", "File Type", width="100%",
choices = list("PDF"="pdf","PNG"="png"))),
column(3, downloadButton('plot1_dl', 'Left Plot')),
column(3, downloadButton('plot2_dl', 'Right Plot'))
)
)
),
tags$style(type='text/css', "#plot1_dl { width:100%; vertical-align:bottom}"),
tags$style(type='text/css', "#plot2_dl { width:100%;}")
)),
server = function(input, output) {
}
))
Run Code Online (Sandbox Code Playgroud)
放置align="bottom"在任何地方和任何地方不会抛出错误消息,但也没有产生预期的效果.尝试使用按钮的样式标签,但我的深度.
我想让我的ggplot传说并排出现在情节下面,变量名称在符号上方,就像它们在这篇博文(第二个情节)中一样.该opts功能现已不存在,theme似乎没有复制其行为......
library("ggplot2")
ggplot(diamonds, aes(x = carat, y=price, shape = cut, group=interaction(cut, color), color=color)) +
geom_point() +
#opts(legend.direction = "horizontal", legend.position = "bottom")
#potential options, not all seem have an effect...
theme(legend.direction = "horizontal") +
theme(legend.position = "bottom") +
theme(legend.box = "vertical") +
theme(legend.title.align = 0)
Run Code Online (Sandbox Code Playgroud)

...使用我的MS绘画技巧来说明所需的情节.
作为函数的一部分,我想输出所有参数及其值的列表,包括默认值.例如,具有以下参数的函数:
foo <- function(x=NULL,y=NULL,z=2) {
#formals()
#as.list(match.call())[-1]
#some other function?....
}
Run Code Online (Sandbox Code Playgroud)
提供输出:
> foo(x=4)
$x
[1] 4
$y
NULL
$z
[1] 2
Run Code Online (Sandbox Code Playgroud)
formals在调用函数时,不会更新以提供values参数值.match.call确实如此,但不提供参数的默认值.那里有另一个功能可以提供我想要的输出吗?
我只需要矩阵乘法中的对角线元素:
,
在R.由于Z很大,我想避免全面的乘法......
Z <- matrix(c(1,1,1,2,3,4), ncol = 2)
Z
# [,1] [,2]
#[1,] 1 2
#[2,] 1 3
#[3,] 1 4
X <- matrix(c(10,-5,-5,20), ncol = 2)
X
# [,1] [,2]
#[1,] 10 -5
#[2,] -5 20
Z %*% D %*% t(Z)
# [,1] [,2] [,3]
#[1,] 70 105 140
#[2,] 105 160 215
#[3,] 140 215 290
diag(Z %*% D %*% t(Z))
#[1] 70 160 290
Run Code Online (Sandbox Code Playgroud)
X始终是一个小方阵(2x2,3x3或4x4),其中Z的列数等于X的维数.是否有可用的函数?
我有一堆具有不同变量的数据框.我想将它们读入R并将列添加到缺少一些变量的列中,这样它们都有一组共同的标准变量,即使有些变量未被观察到.
换句话说...... NA当列不存在时,有没有办法在tidyverse中添加列?我当前的尝试适用于在列不存在的情况下添加新变量(top_speed)但在列已经存在时失败(mpg)(它将所有观察设置为第一个值Mazda RX4).
library(tidyverse)
mtcars %>%
tbl_df() %>%
rownames_to_column("car") %>%
mutate(top_speed = ifelse("top_speed" %in% names(.), top_speed, NA),
mpg = ifelse("mpg" %in% names(.), mpg, NA)) %>%
select(car, top_speed, mpg, everything())
# # A tibble: 32 x 13
# car top_speed mpg cyl disp hp drat wt qsec vs am gear carb
# <chr> <lgl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
# 1 Mazda RX4 NA 21 6 160.0 …Run Code Online (Sandbox Code Playgroud) 我正在尝试获取一些R代码以适应我的beamer幻灯片.似乎不可能通过size代码块的参数更改字体大小,就像对其他knitr类型文档一样.唯一的方法似乎是\footnotesize在每个代码块之前.这是令人沮丧的,因为我有很多代码块,在许多情况下,我必须使用\normalsize之后我的LaTeX项目符号点.
---
title: "Untitled"
output:
beamer_presentation:
includes:
in_header: header.txt
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, size = "footnotesize")
```
## R Markdown
```{r}
summary(cars)
```
\footnotesize
```{r}
summary(cars)
```
Run Code Online (Sandbox Code Playgroud)
在我header.txt(下面)中,我已经尝试了一些来自http://yihui.name/knitr/demo/beamer/的代码,但没有运气.
\ifdefined\knitrout
\renewenvironment{knitrout}{\begin{footnotesize}}{\end{footnotesize}}
\else
\fi
\makeatletter
\let\oldalltt\alltt
\def\alltt{\@ifnextchar[\alltt@i \alltt@ii}
\def\alltt@i[#1]{\oldalltt[#1]\footnotesize}
\def\alltt@ii{\oldalltt\footnotesize}
\makeatother
Run Code Online (Sandbox Code Playgroud)
......但真的超出我的深度\def.
我正在尝试创建一个facet_multi_col()函数,该facet_col()函数类似于中的函数ggforce-允许使用空格参数(在中不可用facet_wrap())进行构面布局-但可以在多个列上使用。就像下面的最后一个图(用创建grid.arrange())一样,我不希望这些小平面必须在行之间对齐,因为每个小平面的高度将根据y我希望使用的类别变量而变化。
ggproto阅读扩展指南后,我发现自己已经完全脱离了深度。我认为最好的方法是传递一个布局矩阵来指示在哪里断开数据对应子集的列,并facet_col 在ggforce中进行构建以包括一个空间参数-请参阅问题的结尾。
我不满意的选择的快速说明
library(tidyverse)
library(gapminder)
global_tile <- ggplot(data = gapminder, mapping = aes(x = year, y = fct_rev(country), fill = lifeExp)) +
geom_tile()
global_tile
Run Code Online (Sandbox Code Playgroud)
global_tile +
facet_wrap(facets = "continent", scales = "free")
Run Code Online (Sandbox Code Playgroud)
facet_wrap()没有空格参数,这表示每个大陆的磁贴大小不同,使用coord_equal()会引发错误
library(ggforce)
global_tile +
facet_col(facets = "continent", scales = "free", space = "free", strip.position = "right") +
theme(strip.text.y = element_text(angle = 0))
Run Code Online (Sandbox Code Playgroud)
加载包装时是否有理由更喜欢使用引号; 例如
library("MASS")
Run Code Online (Sandbox Code Playgroud)
过度加载包而不将名称放在引号中;
library(MASS)
Run Code Online (Sandbox Code Playgroud)
回顾一些旧的代码,我似乎在两者之间切换,没有明显的后果.是否有最佳实践建议?