使用github操作运行r rmd文件
我有两个存储库每天只需在Rstudio打开项目并编织RMD文件,然后将结果推向存储库,可以每天更新。
我很想通过github动作自动化这一点,但是我发现文档很困惑。
在做这件事时,是否有“像我5岁的人”来解释吗?
因此,我制作了一个bash文件,位于./ bash/data_refresh.sh.sh
和一个github操作文件data_refresh.yaml
bash文件:
#!/bin/bash
echo "Rendering the page..."
Rscript -e "rmarkdown::render(input = 'README.Rmd')"
if [[ "$(git status --porcelain)" != "" ]]; then
git config --global user.name 'my_user_name'
git config --global user.email 'my_email_address'
git add *
git commit -m "Auto update Report"
git push
fi
这是我的yaml
:
# This is a basic workflow to help you get started with Actions
name: Package Data Refresh
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "master" branch
schedule:
- cron: '0 12 * * *'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
name: refresh the dashboard
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: checkout_repo
uses: actions/checkout@v2
with:
ref: 'master'
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Render Rmarkdown
run: bash ./bash/data_refresh.sh
我遇到以下错误,不确定如何纠正它。
Run bash ./bash/data_refresh.sh
bash ./bash/data_refresh.sh
shell: /usr/bin/bash -e {0}
Rendering the page...
Error in loadNamespace(x) : there is no package called ‘rmarkdown’
Calls: loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart
Execution halted
I have two repositories that I update daily by simply opening the project in RStudio and knitting the RMD file, then pushing the results to the repo.
I would love to automate this with GitHub actions but I find the documentation highly confusing.
Is there an "Explain it like I'm 5" on doing this particular thing?
So I made a bash file located at ./bash/data_refresh.sh
and a github actions file data_refresh.yaml
Bash file:
#!/bin/bash
echo "Rendering the page..."
Rscript -e "rmarkdown::render(input = 'README.Rmd')"
if [[ "$(git status --porcelain)" != "" ]]; then
git config --global user.name 'my_user_name'
git config --global user.email 'my_email_address'
git add *
git commit -m "Auto update Report"
git push
fi
Here is my yaml
:
# This is a basic workflow to help you get started with Actions
name: Package Data Refresh
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "master" branch
schedule:
- cron: '0 12 * * *'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
name: refresh the dashboard
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: checkout_repo
uses: actions/checkout@v2
with:
ref: 'master'
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Render Rmarkdown
run: bash ./bash/data_refresh.sh
I am getting the following error and not sure how to rectify it.
Run bash ./bash/data_refresh.sh
bash ./bash/data_refresh.sh
shell: /usr/bin/bash -e {0}
Rendering the page...
Error in loadNamespace(x) : there is no package called ‘rmarkdown’
Calls: loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart
Execution halted
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以取从
r-lib 作为起点并添加您的零件(渲染& cron作业)。
当手动触发时,这起作用了,我尚未测试cron作业:
这使用
renv
安装依赖项并缓存GHA中的依赖项(据我了解)。因此,您需要在存储库中使用renv
。只需使用renv :: init()
并提交结果文件。当您使用.rmd
时,这包括rmarkDown
。有关更多信息,请检查
文档。renv
rentv使其起作用的关键部分是,您必须在参数周围使用
rscript
的单个引号,而不是双引号。否则它将无法正常工作。另外,我是GHA的新手,因此您可能还可以优化其他方面。
在此处编辑
是一个无需
renv
的版本,但是我建议使用renv
,因为它允许缓存依赖关系(套件)。You can take the workflows from
r-lib
as a starting point and add your parts (rendering & cron job).This works when triggered manually, I haven't tested the cron job:
This uses
renv
to install the dependencies and cache the dependencies in GHA (as far as I understand). Therefore, you need to userenv
in your repository. Simply userenv::init()
and commit the resulting files. As you use.Rmd
, this includesrmarkdown
. For more information, check therenv
documentation.The crucial part to make it work is that you have to use single quotes around the argument for
Rscript
, not double quotes. Otherwise it won't work.Also, I'm quite new to GHA, so there might be other aspects you could optimise.
Edit
Here is a version that works without
renv
, however I recommend usingrenv
as it allows to cache your dependencies (packages).