(This article was first published on Dan Kelley Blog/R, and kindly contributed to Rbloggers)
A previous posting explained how to install WebTide on an OSX machine. This one shows how to hook up to an installed WebTide database, so that R code can get tidal predictions.
The following code in the R language will produce a graph in which the top panel mimics the tidalelevation graph produced by WebTide itself (see previous blog posting for comparison).

library(oce)
tStart < as.POSIXct("20131229 14:21:00", tz="UTC")
tEnd < as.POSIXct("20140113 15:21:00", tz="UTC")
time<seq(tStart, tEnd, by=15, units="minutes")
prediction < webtide("predict", lon=65.06747, lat=45.36544, time=time)

One of the advantages of accessing the tidal prediction from within oce is to make it easier to undertake further analysis, e.g. a node nearer Halifax has a mixed tide, with the following illustrating in terms of velocity and a socalled progressive vector.

p < webtide("predict", node=14569)
par(mfrow=c(2,1), mar=c(3, 3, 1, 1), mgp=c(2, 0.7, 0))
plot(p$u, p$v, asp=1, type="o")
dt < diff(as.numeric(p$time[1:2]))
x < dt * cumsum(p$u)
y < dt * cumsum(p$v)
plot(x, y, asp=1, type="o")

To leave a comment for the author, please follow the link and comment on their blog: Dan Kelley Blog/R.
Rbloggers.com offers daily email updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...