Bearloga has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/364000 )

Change subject: Add lint checking & update doc formatting
......................................................................

Add lint checking & update doc formatting

This is mostly just to test CI.

Bug: T153856
Change-Id: I605a2a1e221850752517cccb9db1ed3c90fcb31a
---
A .lintr
M DESCRIPTION
M R/dwell.R
M R/ortiz.R
M man/dwell_time.Rd
M tests/testthat.R
A tests/testthat/test-syntax.R
7 files changed, 60 insertions(+), 28 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/discovery/ortiz 
refs/changes/00/364000/1

diff --git a/.lintr b/.lintr
new file mode 100644
index 0000000..30b9cf8
--- /dev/null
+++ b/.lintr
@@ -0,0 +1,5 @@
+linters: with_defaults(line_length_linter(120), object_usage_linter = NULL, 
closed_curly_linter = NULL, open_curly_linter = NULL)
+exclusions: list("R/RcppExports.R")
+exclude: "# Exclude Linting"
+exclude_start: "# Begin Exclude Linting"
+exclude_end: "# End Exclude Linting"
diff --git a/DESCRIPTION b/DESCRIPTION
index 4168ee5..8ccc758 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,8 +1,10 @@
 Package: ortiz
 Title: Speedy User Satisfaction Computations
-Version: 0.0.3
-Author: Oliver Keyes
-Maintainer: Mikhail Popov <mpo...@wikimedia.org>
+Version: 0.0.4
+Authors@R: c(
+    person("Mikhail", "Popov", email = "mikh...@wikimedia.org", role = 
c("aut", "cre")),
+    person("Oliver", "Keyes", role = "aut", comment = "No longer employed at 
the Foundation")
+    )
 Description: Speedily computes various user satisfaction-related metrics for
     Search.
 License: MIT + file LICENSE
@@ -11,6 +13,9 @@
     projects=Discovery
 LinkingTo: Rcpp
 Imports: Rcpp
-Suggests: testthat
+Suggests:
+    lintr,
+    testthat
 LazyData: true
+Roxygen: list(markdown = TRUE)
 RoxygenNote: 6.0.1
diff --git a/R/dwell.R b/R/dwell.R
index 3b5e705..d3361ef 100644
--- a/R/dwell.R
+++ b/R/dwell.R
@@ -1,21 +1,28 @@
-#'@title Identify User Satisfaction Rate Based on Dwell Time
+#' @title Identify User Satisfaction Rate Based on Dwell Time
+#' @description One simple satisfaction heuristic is to look at the dwell time
+#'  a user has on each page in a session and whether any one of those
+#'  dwell-times exceeds a certain threshold. If it does, that session is deemed
+#'  to be one in which the user was satisfied. `dwell_time` calculates
+#'  that for a data.frame of user sessions.
+#' @param data a `data.frame` containing session data
+#' @param id_col the name or index of the column containing unique session IDs
+#' @param ts_col the name or index of the column containing timestamps
+#' @param dwell_threshold the value (in seconds) to use to indicate a
+#'  "successful" session
+#' @examples
+#' # Data:
+#' ts <- as.POSIXct(
+#'   c("2016-03-01T06:52:49Z", "2016-03-01T06:53:19Z", "2016-03-01T06:53:39Z"),
+#'   format = "%Y-%m-%dT%H:%M:%SZ", tz = "UTC"
+#' )
+#' x <- data.frame(timestamp = ts, session_id = "0024c4506bf92e1c")
 #'
-#'@description One simple satisfaction heuristic is to look at the dwell time
-#'a user has on each page in a session and whether any one of those
-#'dwell-times exceeds a certain threshold. If it does, that session is deemed
-#'to be one in which the user was satisfied. \code{dwell_time} calculates
-#'that for a data.frame of user sessions.
+#' # Use default threshold:
+#' dwell_time(x, "session_id", "timestamp")
 #'
-#'@param data a data.frame containing session data
-#'
-#'@param id_col the name or index of the column containing unique session IDs
-#'
-#'@param ts_col the name or index of the column containing timestamps
-#'
-#'@param dwell_threshold the value (in seconds) to use to indicate a 
"successful"
-#'session.
-#'
-#'@export
+#' # Use 10s threshold:
+#' dwell_time(x, "session_id", "timestamp", 10)
+#' @export
 dwell_time <- function(data, id_col, ts_col, dwell_threshold = 100) {
 
   # Check type. We need timestamps to end up as numeric seconds 
representations,
diff --git a/R/ortiz.R b/R/ortiz.R
index 38696be..541ed55 100644
--- a/R/ortiz.R
+++ b/R/ortiz.R
@@ -1,8 +1,5 @@
-
 #' @title Speedy User Satisfaction Computations
-#'
 #' @description Speedily computes various user satisfaction-related metrics 
for Search.
-#'
 #' @docType package
 #' @name ortiz
 #' @useDynLib ortiz
diff --git a/man/dwell_time.Rd b/man/dwell_time.Rd
index 989f413..a1f5ae3 100644
--- a/man/dwell_time.Rd
+++ b/man/dwell_time.Rd
@@ -7,14 +7,14 @@
 dwell_time(data, id_col, ts_col, dwell_threshold = 100)
 }
 \arguments{
-\item{data}{a data.frame containing session data}
+\item{data}{a \code{data.frame} containing session data}
 
 \item{id_col}{the name or index of the column containing unique session IDs}
 
 \item{ts_col}{the name or index of the column containing timestamps}
 
-\item{dwell_threshold}{the value (in seconds) to use to indicate a "successful"
-session.}
+\item{dwell_threshold}{the value (in seconds) to use to indicate a
+"successful" session}
 }
 \description{
 One simple satisfaction heuristic is to look at the dwell time
@@ -23,3 +23,17 @@
 to be one in which the user was satisfied. \code{dwell_time} calculates
 that for a data.frame of user sessions.
 }
+\examples{
+# Data:
+ts <- as.POSIXct(
+  c("2016-03-01T06:52:49Z", "2016-03-01T06:53:19Z", "2016-03-01T06:53:39Z"),
+  format = "\%Y-\%m-\%dT\%H:\%M:\%SZ", tz = "UTC"
+)
+x <- data.frame(timestamp = ts, session_id = "0024c4506bf92e1c")
+
+# Use default threshold:
+dwell_time(x, "session_id", "timestamp")
+
+# Use 10s threshold:
+dwell_time(x, "session_id", "timestamp", 10)
+}
diff --git a/tests/testthat.R b/tests/testthat.R
index f299b9e..b1db86a 100644
--- a/tests/testthat.R
+++ b/tests/testthat.R
@@ -1,5 +1,3 @@
-Sys.unsetenv("R_TESTS")
-
 library(testthat)
 library(ortiz)
 
diff --git a/tests/testthat/test-syntax.R b/tests/testthat/test-syntax.R
new file mode 100644
index 0000000..f5c29db
--- /dev/null
+++ b/tests/testthat/test-syntax.R
@@ -0,0 +1,6 @@
+if (requireNamespace("lintr", quietly = TRUE)) {
+  context("lints")
+  test_that("Package Style", {
+    lintr::expect_lint_free()
+  })
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/364000
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I605a2a1e221850752517cccb9db1ed3c90fcb31a
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/discovery/ortiz
Gerrit-Branch: master
Gerrit-Owner: Bearloga <mpo...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to