儿童降价打印未知的零值
我正在做调查报告,我需要反复产生相同的李克特量表问题分析。我正在使用孩子的降价变成功能和PMAP。儿童降级会产生一个频率响应表,并带有使用Ggiraph制作的工具提示的图。
孩子的降价按照我使用的方法的函数的目的工作,但是它在最后一个选项卡的底部打印了“ [[i]]'null。
我无法记录。在下面的repex中,如果要渲染此标记,然后单击问题2的“绘图”选项卡,这是null值打印的位置。
我的主要降价文档的代码如下,并不是Repex所需的所有软件包,而是我在Actaul项目中使用的所有软件包。
```{r, echo = FALSE, warning = FALSE, message = FALSE}
library(tidyverse)
library(readxl)
library(kableExtra)
library(janitor)
library(xlsx)
data <- data.frame(question_1 = sample(c("Never",
"Rarely",
"Sometimes",
"Often",
"Always",
NA),
replace = TRUE,
size = 100),
question_2 = sample(c("Never",
"Rarely",
"Sometimes",
"Often",
"Always",
NA),
replace = TRUE,
size = 100))
questions_list <- data.frame(title = c("How often do you drink water",
"How often do you exercise"),
variable = c("question_1",
"question_2"),
variable_title = c("Question 1",
"Question 2"))
Child_function <- function(variable,
title,
variable_title){
child_env <- new.env()
child_env$variable <- variable
child_env$title <- title
child_env$variable_title <- variable_title
res <- knitr::knit_child(
"C:/PROJECT-CLONES/REPEX/Questions-Child.Rmd",
envir = child_env,
quiet = TRUE
)
cat(res, sep = "\n")
}
```
```{r, results = 'asis', echo = FALSE}
pmap(questions_list, Child_function)
```
这里的代码是产生问题分析的子降级的代码。
---
output: html_document
---
```{r, echo = FALSE, warning = FALSE}
library(tidyverse)
library(readxl)
library(knitr)
library(kableExtra)
library(ggiraph)
data%>%
select(contains(variable)) -> data
names(data)[1] <- "variable"
```
## `r variable_title` {.tabset}
<h4>`r title`</h4>
### Frequency Table
```{r, echo = FALSE}
Response_Options <- data.frame(variable = c("Never",
"Rarely",
"Sometimes",
"Often",
"Always",
"No response"))
data%>%
mutate(variable = ifelse(is.na(variable),
"No response",
variable))%>%
group_by(variable)%>%
summarise(Count = n())%>%
ungroup()%>%
mutate(Percent = (Count/sum(Count)) * 100)%>%
full_join(Response_Options, by = "variable")%>%
mutate_at(vars(Count, Percent),
as.character)%>%
mutate(Count = ifelse(is.na(Count),
"0",
Count))%>%
mutate(Percent = ifelse(is.na(Percent),
"0",
Percent))%>%
mutate_at(vars(Count, Percent),
as.numeric)%>%
mutate(variable = factor(variable,
levels = c("Never",
"Rarely",
"Sometimes",
"Often",
"Always",
"No response")))%>%
arrange(variable) -> Frequency_table
Frequency_table%>%
mutate(Percent = round(Percent, digits = 1))%>%
kable(caption = "",
col.names = c("Response",
"Frequency",
"Percentage"))%>%
kable_styling(bootstrap = "bordered")
```
### Plot
```{r, echo = FALSE}
Frequency_table%>%
ggplot(mapping = aes(x = variable,
y = Percent))+
geom_bar(stat = 'identity')+
geom_bar_interactive(stat = "identity",
width = 1,
color = "black",
fill = "#EC833A",
aes(tooltip = paste0(variable,
": ",
as.character(round(Percent, digits = 1)),
"%")))+
labs(title = "Response Distribution",
y = "Percent",
x = "")+
theme_light()+
theme(plot.title = element_text(hjust = 0),
axis.line = element_line(size = .2),
panel.grid = element_line(linetype = 2, color = "#6d6e71"),
panel.border = element_blank(),
plot.caption = element_text(color = "#6d6e71",
hjust = 0),
axis.text.x = element_text(angle = 45, vjust = 1, hjust=1)) -> Plot
Plot_Interact <- girafe(ggobj = Plot)
Plot_Interact
```
为长期的重复表示歉意。我一直在试图整个早晨弄清楚这一点,并非常感谢任何帮助。我试图在孩子降价中评论所有部分代码,以查看可能产生的零件,但我没有运气。
Im doing survey reporting and I need to produce the same likert scale question analysis repeatedly. I am doing this using a Child Markdown turned into a function and pmap. The child markdown produces a frequency response table, and a plot with tool tips made using ggiraph.
The child markdown works as intended in a function with the method I am using, however it prints '[[i]]' Null at the bottom of the last tab.
I have not been able to trackdown. In the repex below, if you are to render this markdown and click on the "Plot" tab for question 2, this is where the NULL values print.
My code for the main markdown document is as follows, not all the packages included are needed for the repex but are all the packages I use in my actaul project.
```{r, echo = FALSE, warning = FALSE, message = FALSE}
library(tidyverse)
library(readxl)
library(kableExtra)
library(janitor)
library(xlsx)
data <- data.frame(question_1 = sample(c("Never",
"Rarely",
"Sometimes",
"Often",
"Always",
NA),
replace = TRUE,
size = 100),
question_2 = sample(c("Never",
"Rarely",
"Sometimes",
"Often",
"Always",
NA),
replace = TRUE,
size = 100))
questions_list <- data.frame(title = c("How often do you drink water",
"How often do you exercise"),
variable = c("question_1",
"question_2"),
variable_title = c("Question 1",
"Question 2"))
Child_function <- function(variable,
title,
variable_title){
child_env <- new.env()
child_env$variable <- variable
child_env$title <- title
child_env$variable_title <- variable_title
res <- knitr::knit_child(
"C:/PROJECT-CLONES/REPEX/Questions-Child.Rmd",
envir = child_env,
quiet = TRUE
)
cat(res, sep = "\n")
}
```
```{r, results = 'asis', echo = FALSE}
pmap(questions_list, Child_function)
```
The code here is the code for the Child Markdown that produces the question analysis.
---
output: html_document
---
```{r, echo = FALSE, warning = FALSE}
library(tidyverse)
library(readxl)
library(knitr)
library(kableExtra)
library(ggiraph)
data%>%
select(contains(variable)) -> data
names(data)[1] <- "variable"
```
## `r variable_title` {.tabset}
<h4>`r title`</h4>
### Frequency Table
```{r, echo = FALSE}
Response_Options <- data.frame(variable = c("Never",
"Rarely",
"Sometimes",
"Often",
"Always",
"No response"))
data%>%
mutate(variable = ifelse(is.na(variable),
"No response",
variable))%>%
group_by(variable)%>%
summarise(Count = n())%>%
ungroup()%>%
mutate(Percent = (Count/sum(Count)) * 100)%>%
full_join(Response_Options, by = "variable")%>%
mutate_at(vars(Count, Percent),
as.character)%>%
mutate(Count = ifelse(is.na(Count),
"0",
Count))%>%
mutate(Percent = ifelse(is.na(Percent),
"0",
Percent))%>%
mutate_at(vars(Count, Percent),
as.numeric)%>%
mutate(variable = factor(variable,
levels = c("Never",
"Rarely",
"Sometimes",
"Often",
"Always",
"No response")))%>%
arrange(variable) -> Frequency_table
Frequency_table%>%
mutate(Percent = round(Percent, digits = 1))%>%
kable(caption = "",
col.names = c("Response",
"Frequency",
"Percentage"))%>%
kable_styling(bootstrap = "bordered")
```
### Plot
```{r, echo = FALSE}
Frequency_table%>%
ggplot(mapping = aes(x = variable,
y = Percent))+
geom_bar(stat = 'identity')+
geom_bar_interactive(stat = "identity",
width = 1,
color = "black",
fill = "#EC833A",
aes(tooltip = paste0(variable,
": ",
as.character(round(Percent, digits = 1)),
"%")))+
labs(title = "Response Distribution",
y = "Percent",
x = "")+
theme_light()+
theme(plot.title = element_text(hjust = 0),
axis.line = element_line(size = .2),
panel.grid = element_line(linetype = 2, color = "#6d6e71"),
panel.border = element_blank(),
plot.caption = element_text(color = "#6d6e71",
hjust = 0),
axis.text.x = element_text(angle = 45, vjust = 1, hjust=1)) -> Plot
Plot_Interact <- girafe(ggobj = Plot)
Plot_Interact
```
Apologies for the long repex. Ive been trying to figure this out all morning and any help is greatly appreciated. Ive tried commenting out all portions of code in the child markdown to see what might be generating the NULLs but I havent had any luck.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以制作
pmap
输出Invisible
:You could make
pmap
outputinvisible
: