Skip to content

Commit 04a40c6

Browse files
committed
Add nearestPOI.R
1 parent 6734d45 commit 04a40c6

31 files changed

+127
-44
lines changed

DESCRIPTION

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: FDBeye
22
Type: Package
33
Title: Functions to Ease Work with Eyetracker Data
4-
Version: 0.0.19
5-
Date: 2016-10-25
4+
Version: 0.0.20
5+
Date: 2017-06-28
66
Authors@R: c(
77
person("David", "Braze", email="davebraze@gmail.com", role=c("aut", "cre")),
88
person("Tao", "Gong", role="aut"),
@@ -20,6 +20,7 @@ Imports:
2020
grid,
2121
plyr,
2222
png,
23+
purrr,
2324
stats,
2425
stringr,
2526
tools,
@@ -35,7 +36,7 @@ License: MIT + file LICENSE
3536
LazyData: true
3637
URL: https://github.com/davebraze/FDBeye
3738
BugReports: https://github.com/davebraze/FDBeye/issues
38-
RoxygenNote: 5.0.1
39+
RoxygenNote: 6.0.1
3940
Suggests:
4041
knitr,
4142
rmarkdown

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export(get_xybounds)
1717
export(inked)
1818
export(makeReport)
1919
export(mark_oob)
20+
export(nearestPOI)
2021
export(readELascii)
2122
export(reg2regdef)
2223
export(regdef2ias)

R/nearestPOI.R

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
##' @title Find the nearest Point of Interest for each fixation.
2+
##'
3+
##' @description For each fixation in a fixation report, this function
4+
##' will determine the nearest Point of Interest and the
5+
##' fixation's distance from that Point of Interest.
6+
##'
7+
##' @details For each fixation in a fixation report, this function
8+
##' will determine the nearest Point of Interest and the
9+
##' fixation's distance from that Point of Interest.
10+
##'
11+
##' The value of \code{supplement} determines whether to return
12+
##' the POI values within an enriched version of \code{fixReport},
13+
##' or as a simple two column data.frame.
14+
##'
15+
##' @param fixReport A fixation Report as may be created by
16+
##' fixReport(). Must contain columns \code{xpos} and \code{ypos}.
17+
##' @param poiList A data.frame containing x,y coordinates for Points
18+
##' of Interest. The data.frame must contain exactly two columns,
19+
##' named \code{xpos} and \code{ypos}, in that order.
20+
##' @param supplement If TRUE, nearestPOI() will return a data.frame
21+
##' consisting of fixReport suplemented with columns nearestpoi
22+
##' and dist2poi. If FALSE return a 2 column data.frame with just
23+
##' those two columns.
24+
##' @return A data.frame including columns nearestpoi and dist2poi.
25+
##' @author Dave Braze <davebraze@@gmail.com>
26+
##' @export
27+
nearestPOI <- function (fixReport, poiList, supplement=TRUE) {
28+
f <- function(fix=fix, poiList=poiList) {
29+
## Find nearest poi for one fixation.
30+
tmp <- rbind(fix[c("xpos", "ypos")], poi) ## should merge rather than rbind
31+
dst <- as.matrix(dist(tmp))[-1,1]
32+
.nearestpoi <- which.min(dst)
33+
names(.nearestpoi) <- NULL
34+
.dist2poi <- min(dst)
35+
retval <- data.frame(nearestpoi=.nearestpoi, dist2poi=.dist2poi)
36+
}
37+
retval <- purrr::by_row(fixReport, f, poi=poi, .collate="row",
38+
.labels=supplement)
39+
select(retval, -matches("^.row$"))
40+
}

man/EToralreading.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/FDBeye.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/adjust_y.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/ascAnon.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/cat_lines1.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/cat_lines2.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/cat_lines3.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)