Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
mkearney committed Oct 16, 2018
1 parent 2b618f0 commit f5a7833
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
^codecov\.yml$
^\.travis\.yml$
^LICENSE\.md$
^README\.Rmd$
^.*\.Rproj$
^\.Rproj\.user$
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r

language: R
sudo: false
cache: packages
10 changes: 10 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,13 @@ LazyData: true
RoxygenNote: 6.1.0.9000
URL: https://github.com/mkearney/qualtricks
BugReports: https://github.com/mkearney/qualtricks/issues
Imports:
tfse,
readr,
tibble,
utils
Suggests:
testthat,
covr
Depends:
R (>= 2.10)
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Generated by roxygen2: do not edit by hand

S3method(read_qualtrics,default)
export(read_qualtrics)
export(recode_likert)
26 changes: 18 additions & 8 deletions R/read_qualtrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@ is_csv <- function(x) {
#'
#' Reads and formats data exported from qualtrics.
#'
#' @param Path to CSV exported from Qualtrics
#' @return A tibble
#' @param x Path to CSV exported from Qualtrics
#' @return A tibble data frame.
#' @export
read_qualtrics <- function(x) {
read_qualtrics <- function(x) UseMethod("read_qualtrics")

#' @export
read_qualtrics.default <- function(x) {
## check to make sure it's a valid csv file
stopifnot(is_csv(x))
## read first three rows
vars <- read.csv(x, header = TRUE, stringsAsFactors = FALSE)
vars <- utils::read.csv(x, header = TRUE, stringsAsFactors = FALSE)
x <- vars[c(3:nrow(vars)), ]
vars <- vars[1, , drop = TRUE]
tmp <- tempfile(fileext = ".csv")
write.csv(x, tmp, row.names = FALSE)
utils::write.csv(x, tmp, row.names = FALSE)
x <- suppressMessages(readr::read_csv(tmp))
## rename some columns
#old <- c("StartDate", "EndDate", "Duration..in.seconds.", "LocationLatitude","LocationLongitude")
Expand Down Expand Up @@ -113,7 +116,7 @@ prep_char_vector <- function(x) {
x
}

recode_likert <- function(x) {
recode_likert_col <- function(x) {
## prep/coerce to char (if factor of single-elem list)
x <- prep_char_vector(x)
## proceed if char
Expand Down Expand Up @@ -209,8 +212,15 @@ recode_likert <- function(x) {
x
}

recode_likerts <- function(x) {
x[1:ncol(x)] <- lapply(x, recode_likert)
#' Recode likert items
#'
#' Converts likert columns into integer columns
#'
#' @param x Input data frame with likert columns
#' @return A data frame with likert choice columns replaced with integer values
#' @export
recode_likert <- function(x) {
x[1:ncol(x)] <- lapply(x, recode_likert_col)
x
}

Expand Down
Binary file added R/sysdata.rda
Binary file not shown.
6 changes: 3 additions & 3 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ knitr::opts_chunk$set(echo = TRUE, collapse = TRUE, comment = "#>")
```
# qualtricks <img src="man/figures/logo.png" width="160px" align="right" />

<!--[![Build status](https://travis-ci.org/mkearney/qualtricks.svg?branch=master)](https://travis-ci.org/mkearney/qualtricks)
[![Build status](https://travis-ci.org/mkearney/qualtricks.svg?branch=master)](https://travis-ci.org/mkearney/qualtricks)
[![CRAN status](https://www.r-pkg.org/badges/version/qualtricks)](https://cran.r-project.org/package=qualtricks)
[![Coverage Status](https://codecov.io/gh/mkearney/qualtricks/branch/master/graph/badge.svg)](https://codecov.io/gh/mkearney/qualtricks?branch=master)

#![Downloads](https://cranlogs.r-pkg.org/badges/qualtricks)
<!--#![Downloads](https://cranlogs.r-pkg.org/badges/qualtricks)
#![Downloads](https://cranlogs.r-pkg.org/badges/grand-total/qualtricks)-->
[![lifecycle](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)

Expand Down Expand Up @@ -47,6 +47,6 @@ Streamlined process for **recoding** Likert items

``` r
## recode likerts (from labels to integers)
qualtricks::recode_likerts(d)
qualtricks::recode_likert(d)
```

15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@

# qualtricks <img src="man/figures/logo.png" width="160px" align="right" />

<!--[![Build status](https://travis-ci.org/mkearney/qualtricks.svg?branch=master)](https://travis-ci.org/mkearney/qualtricks)
[![CRAN status](https://www.r-pkg.org/badges/version/qualtricks)](https://cran.r-project.org/package=qualtricks)
[![Coverage Status](https://codecov.io/gh/mkearney/qualtricks/branch/master/graph/badge.svg)](https://codecov.io/gh/mkearney/qualtricks?branch=master)
#![Downloads](https://cranlogs.r-pkg.org/badges/qualtricks)
[![Build
status](https://travis-ci.org/mkearney/qualtricks.svg?branch=master)](https://travis-ci.org/mkearney/qualtricks)
[![CRAN
status](https://www.r-pkg.org/badges/version/qualtricks)](https://cran.r-project.org/package=qualtricks)
[![Coverage
Status](https://codecov.io/gh/mkearney/qualtricks/branch/master/graph/badge.svg)](https://codecov.io/gh/mkearney/qualtricks?branch=master)

<!--#![Downloads](https://cranlogs.r-pkg.org/badges/qualtricks)
#![Downloads](https://cranlogs.r-pkg.org/badges/grand-total/qualtricks)-->

[![lifecycle](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
Expand Down Expand Up @@ -41,5 +44,5 @@ Streamlined process for **recoding** Likert items

``` r
## recode likerts (from labels to integers)
qualtricks::recode_likerts(d)
qualtricks::recode_likert(d)
```
12 changes: 12 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
comment: false

coverage:
status:
project:
default:
target: auto
threshold: 1%
patch:
default:
target: auto
threshold: 1%
4 changes: 2 additions & 2 deletions man/read_qualtrics.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions man/recode_likert.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
library(testthat)
library(qualtricks)

test_check("qualtricks")
16 changes: 16 additions & 0 deletions tests/testthat/test-read_qualtrics.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
context("test-read_qualtrics")

test_that("read_qualtricks works", {
## save test data as csv file
tmp <- tempfile(fileext = ".csv")
write.csv(qualtest, tmp, row.names = FALSE)
on.exit(unlink(tmp), add = TRUE)
d <- read_qualtrics(tmp)
expect_true(is.data.frame(d))
expect_equal(ncol(d), 145)
expect_equal(nrow(d), 276)
d <- recode_likert(d)
expect_equal(ncol(d), 145)
expect_equal(nrow(d), 276)
expect_true(is.integer(d$pic_1))
})

0 comments on commit f5a7833

Please sign in to comment.