Installing the tstools package
I created the tstools
package to polish some of the rough edges associated with time
series analysis in R. The package is not available through CRAN, so
don’t try to install it using install.packages. In fact,
there was a different tstools package on CRAN (first uploaded in 2018,
many years after the first release of my package) that is no longer
there. If you install that package - which has nothing to do with mine -
your programs will not run.
Installation Instructions
You need to use the devtools package to install tstools. First install devtools in the usual way:
install.packages("devtools")
Once that’s installed:
devtools::install_github("bachmeil/tstools")
Testing Your Installation
You can test your installation by checking if the following code runs and gives the expected output:
library(tstools)
x <- ts(1:10)
lags(x, 1:2)
The output should look like this:
Time Series:
Start = 3
End = 11
Frequency = 1
xL1 xL2
3 2 1
4 3 2
5 4 3
6 5 4
7 6 5
8 7 6
9 8 7
10 9 8
11 10 9
Warning
Do not include the install_github line as part
of your program!!!
Doing that will make your program run slowly, because you’ll be downloading and installing the package every time you run your program. You’ll be wasting lots of bandwidth downloading the package for no reason. Once the package is installed, you don’t need to install it again unless a new version has been released and you want to upgrade to it. You should expect Github to block your IP address if you do this repeatedly.
I added this warning because I had a student tell me he avoided tstools because it made his program run very slowly. It took hours to do what should have required at most a few seconds.
I was curious about that, because tstools is a regular R package and
should have no effect on how fast anything else runs. I asked to see his
program. Not only was he installing tstools for no reason every time he
ran his program, he was doing it inside a loop, with option
force=TRUE to force a new download and installation. The
code on the inside of the loop only took a fraction of a second to run,
but it took a long time to download and install the package on every
iteration.
Last updated: August 28, 2026