I am quite new to R but it seems, this question is closely related to the following post 1, 2, 3 and a bit different topic 4. Unfortunately, I have not enough reputation to comment right there. My problem is that after going through all the suggestions there, the code still does not work:
"J" not found in routes[J(lat1, lng1, lat2, lng2), .I, roll = "nearest", by = .EACHI]
instead of 'lat1' not found in routes[order(lat1, lng1, lat2, lng2, time)]
)Thank you very much for your support!
Edit: @Roland
#' @import data.table
to the function. Do you understand, why only inserting Depends: data.table
in the DESCRIPTION file does not work? This might be a useful hint in the documentation or did I miss it?Answering your questions (after edit).
Almost always packages mentioned in ‘Depends’ should also be imported from in the NAMESPACE file: this ensures that any needed parts of those packages are available when some other package imports the current package.
So you still should have import in NAMESPACE despite the fact if you depends or import data.table.
order
call doesn't seems to be what you expect, try the following:order("lat1", "lng1", "lat2", "lng2", "time")
library(data.table)
data.table(a=2:1,b=1:2)[order("a","b")]
In case of issues I recommend to start debugging by writing unit test for your expected results. The most basic way to put unit tests in package is just plain R script in tests
directory having stopifnot(...)
call. Be aware you need to library/require your package at the start of the script.