I read this topic: R command for setting working directory to source file location
But this function prints error:
this.dir <- dirname(parent.frame(2)$ofile)
setwd(this.dir)
Error in dirname(parent.frame(2)$ofile) : a character vector argument expected
How can I set working directory to source file location?