I think this is what you are looking for:
file.copy(sys.frame(1)$ofile,
to = file.path(dirname(sys.frame(1)$ofile),
paste0(Sys.Date(), ".R")))
This will take the current file and copy it to a new file in the same directory as currentDate.R, for example, 2015-07-14.R
If you want to copy to the working directory instead of the source script directory, use
file.copy(sys.frame(1)$ofile,
to = file.path(getwd(),
paste0(Sys.Date(), ".R")))
, sys.frame(1)$ofile , , . , . , .
:
TBH, , , , ( - ), . , , R , source , ofile . (1) (source()) , ( 0). , /, Global ( ), - .
, :
> sys.frame(1)
Error in sys.frame(1) : not that many frames on the stack
:
> myf <- function() sys.frame(1)
> myf()
<environment: 0x0000000013ad7638>
, , ofile:
> myf <- function() names(sys.frame(1))
> myf()
character(0)