Updated based on MichaelChirico feedback and comments by Arun and Soheil .
Roughly speaking, there are two approaches that you could consider. The first is to create a dependency in the package itself, and the second - in the lines of your R-code that check for data.table (and maybe even install it automatically if it is not found).
data.table FAQ specifically describes this in 6.9 and states that you can ensure that data.table your package loaded correctly:
Either i) include data.table in the Depends: field in the DESCRIPTION file, or ii) include data.table in the Importports field of your DESCRIPTION AND import (data.table) file in the NAMESPACE file.
As noted in the comments, this is the usual behavior of R, which is found in numerous packages.
An alternative approach is to create specific lines of code that check and import the necessary packages as part of your code. This, I would argue, is not an ideal solution, given the elegance of using the above options. However, this is technically possible.
An easy way to do this would be to use require or library to check for the existence of data.table with an error if it cannot be attached. You can even use a simple set of conditional statements to run install.packages to install what you need if the download fails.
Yihui Xie (of knitr fame) has a great post about the difference between library and require here and makes a strong case for using library in cases where the package is absolutely necessary for the upcoming code.
source share