kittygirl
kittygirl

Reputation: 2443

`aliases` is not working with `root.dir` in knitr `opts_knit$set`?

In the knitr manual:

aliases: (NULL) a named character vector to specify the aliases of chunk options

As my directory name is long, I want to use aliases as below:

knitr::opts_knit$set(aliases = c(mydir = 'E:/web/cel/ae repo/middle temp data/20190303'), root.dir = mydir,base.dir = mydir)

But I got the error: can not find object mydir. Where is the problem?

Upvotes: 2

Views: 73

Answers (1)

CL.
CL.

Reputation: 14957

I think you're misunderstanding how the package option aliases works:

  1. It allows you to define aliases for the name of an option, not shortcuts for option values.
  2. In your sample code, you try to use the alias as value (see point 1) for a package option. Aliases are alternative names of chunk options.

To achieve what you're apparently trying to do, just define a new object mydir and use it when setting the package options:

mydir <- 'E:/web/cel/ae repo/middle temp data/20190303'
knitr::opts_knit$set(root.dir = mydir, base.dir = mydir)

Upvotes: 2

Related Questions