Hello!
I'm getting an error on Travis that I can't reproduce on my local computer. (e.g. I close and re-open Rstudio, open project, run CMD check, things are dandy, push to GitHub, travis fails). So, I feel like I'm just making a silly mistake, but I'm hoping someone here can help pinpoint it.
At the bottom of this message, I'll show the full error trace from Travis, and the test that sparked it. Right below, I'll post a reprex that I think should reproduce the problem but doesn't. This post will be a bit long, so let me know if it would be better if I shortened it.
Versions of this question have been asked before, here and here.
Do you have any idea what could be happening here? Am I just missing a travis dependency? (yaml at bottom of post)
Reprex
Unfortunately, for this reprex, you'll need to install.github("vrunge/gfpop")
because I'm not sure whether or not the error is related to the dataframe that gfpop::graph
produces.
Main
library(dplyr)
library(gfpop)
library(rlang)
select_graph_columns <- function(graph_df) {
graph_df %>% dplyr::select(.data$state1, .data$state2, .data$type, .data$parameter,
.data$penalty, .data$K, .data$a, .data$min, .data$max)
}
graph <- gfpop::graph(type = "std")
newgraph <- graph
newgraph$test <- c(1,2)
select_graph_columns(newgraph)
Reprex dependencies
if (!requireNamespace("dplyr", quietly = TRUE)) {
install.packages("dplyr")
}
if (!requireNamespace("devtools", quietly = TRUE)) {
install.packages("devtools")
}
if (!requireNamespace("rlang", quietly = TRUE)) {
install.packages("rlang")
}
if (!requireNamespace("gfpop", quietly = TRUE)) {
devtools::install_github("vrunge/gfpop")
}
Problem
This reprex works as-expected on my local machine. But, on my travis build, I think it generates an error (gfpopgui is the package where I defined the select_graph_columns function above):
6. gfpopgui::select_graph_columns(newgraph)
11. dplyr::select(...)
17. tidyselect::eval_select(expr(c(...)), .data)
18. tidyselect:::eval_select_impl(...)
19. vctrs::vec_assert(x)
20. vctrs:::stop_scalar_type(x, arg)
21. vctrs:::stop_vctrs(msg, "vctrs_error_scalar_type", actual = x)
Full test/example
This is basically the same thing as the reprex.
Full travis trace
── 1. Error: select_graph_columns does its job (@test-graph-helpers.R#8) ──────
`x` must be a vector, not a `data.frame/graph` object.
Backtrace:
1. testthat::expect_true(all.equal(graph, select_graph_columns(newgraph)))
6. gfpopgui::select_graph_columns(newgraph)
11. dplyr::select(...)
17. tidyselect::eval_select(expr(c(...)), .data)
18. tidyselect:::eval_select_impl(...)
19. vctrs::vec_assert(x)
20. vctrs:::stop_scalar_type(x, arg)
21. vctrs:::stop_vctrs(msg, "vctrs_error_scalar_type", actual = x)
Full function
#' Selects the columns from this graph dataframe that are relevant to gfpop
#' @param graph_df the graph to process
#' @returns a dataframe with 9 columns, compatable with gfpop
#' @importFrom dplyr select
#' @importFrom rlang .data
#' @import gfpop
#' @examples
#' graph <- gfpop::graph(type = "std")
#' graph$test <- c(1,2)
#' select_graph_columns(graph)
#' @export
select_graph_columns <- function(graph_df) {
graph_df %>% dplyr::select(.data$state1, .data$state2, .data$type, .data$parameter,
.data$penalty, .data$K, .data$a, .data$min, .data$max)
}
Full test
test_that("select_graph_columns does its job", {
graph <- gfpop::graph(type = "std")
newgraph <- graph
newgraph$test <- c(1,2)
expect_equal(all.equal(graph, newgraph),
"Length mismatch: comparison on first 9 components")
expect_true(all.equal(graph, select_graph_columns(newgraph)))
})
travis.yml
language: R
cache: packages
warnings_are_errors: false
r_packages:
- covr
- rsconnect
- devtools
- memoise
- parsedate
- plyr
- rappdirs
- rcmdcheck
- rematch
- rhub
- rversions
- RSelenium
- dplyr
- rlang
- plyr
after_success:
- Rscript -e 'covr::codecov()'
# Added for RSelenium tests
services:
- docker
before_install:
- docker pull selenium/standalone-firefox
- docker run -d --net=host -p 127.0.0.1:4444:4444 selenium/standalone-firefox
# Added for shinyapps.io autodeploy
r_github_packages:
- julianstanley/gfpop-gui