How to set current file location as work directory in R markdown?

后端 未结 1 908
感动是毒
感动是毒 2021-01-15 02:23

I have mydata.RDATA to be used in R, then I need to load(), which means I need to setwd() curent directory first. I already know how to do it in R.

When I do it in R

相关标签:
1条回答
  • 2021-01-15 02:29

    If your .Rmd file is in a subfolder you need to specify the root directory for knitr, even if you've specified a working directory with setwd() or even an RSudio project.

    Fortunately this is as easy as adding the following chunk to the start of your .Rmd file, right after the YAML:

    {r "setup", include=FALSE} require("knitr") opts_knit$set(root.dir = "~/path/to/project")

    The ~/ is your HOME directory on Linux (and maybe Mac). If you're on Windows you'll have to tweak this.

    0 讨论(0)
提交回复
热议问题