How to reload current R script file with a command after it has been changed by another program?
edit:
Assume there is an initial file called test.R with following content:
1 # a random number
y <- readLines("test.R") # read the script
x <- as.numeric(y[1]) # convert the number to numeric
x <- x + 1 # increase the number by 1
y[1] <- x # assign the value to y
print(y[1])
writeLines(y, "test.R") # replace the old file by the new file
and now I would like to reload the current file such that the content is updated within the file itself. Since a couple of years RStudio has a reloading feature, but I cannot wait until RStudio's update signal is triggered. I want to trigger it myself. This is relevant because I would like to write a R function which generates a table of content automatically for xaringan.
linked question on SO.