【问题标题】:Why can't I knit in rmarkdown?为什么我不能在 rmarkdown 中编织?
【发布时间】:2021-08-16 16:32:44
【问题描述】:

我已经在 R 脚本中成功编写了我的代码,但是当我尝试在 Rmarkdown 中编织时,我收到以下错误。 "

我试过了:

  1. 将包安装到 Rmarkdown 中
  2. 使用不同的环境(R studio cloud 和桌面 R)得到完全相同的结果。我认为这意味着我的代码有问题,但只有当我尝试编织时。如果我在 rmarkdown 中运行代码,一切正常。但我无法编织到 html。

下面是我的脚本代码:

View(Daily_log_weight)

myweight <- Daily_log_weight%>%
  clean_names

View(myweight)

#Example: ggplot(data=heartrate_seconds_clean) + geom_bar(mapping=aes(y=value), color='purple')

#Lesson learned: Only things pertaining to an function should go into that function. Geom_point,  labs, etc.

chart1 <- ggplot(data=myweight) + geom_point(mapping=aes(x=day,y=morning_weight), color='orange') + labs(x="The Day", y="My Morning Weight", title = "My Awesome Weightloss Journey", subtitle = "By Naomi Narcisse")

chart1


chart2 <- ggplot(data=myweight) + geom_smooth(mapping=aes(x=day,y=after_workout_weight), color='turquoise') + labs(x="The Day", y="After Workout Weight", title = "Continued.. . After workout", subtitle = "By Naomi Narcisse")

chart2


chart3 <- ggplot(data=myweight) + geom_jitter(mapping=aes(x=morning_weight,y=after_workout_weight), color='dark green', fill='light pink') + labs(x="My Morning Weight", y="My After-Workout Weight", title = "Comparison Weightloss", subtitle = "By Naomi Narcisse")

chart3

【问题讨论】:

  • 查看 RMD 脚本的第 22 行 - 这就是错误的来源。也许与安装软件包有关?
  • 还有必要避免在 RMarkdown 代码上放置“视图”,因为它只允许您在 R 上打开表格
  • 您可能已经在 R 会话中安装了库,但请确保在脚本开头添加 library(PACKAGE_NAME)。当您逐行运行每一行代码时它是否有效,但是当您尝试一次运行整个脚本时会出错?
  • 感谢您的建议。到目前为止,我发现 knit 可以处理“汽车”数据。但不是我的 csv 导入文件。我会继续努力,但任何其他建议都会很棒。

标签: r ggplot2 r-markdown knitr


【解决方案1】:

如果一切都失败了,请重新安装 R、RStudio 和所有软件包。 Windows 用户也应该安装 Rtools 来处理软件包的安装。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-30
    • 2021-07-24
    • 1970-01-01
    • 2020-03-27
    相关资源
    最近更新 更多