`x` must be a vector: travis, but not local

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

Ahh, apologies--I think I see the problem now.

I decided to go to rstudio.cloud to debug--it actually seems like a really great tool for testing my package in a separate environment.

It has to do with the graph class that my dataframes have, doesn't seem to sit well with dplyr::select:

> test1 <- structure(list(state1 = c("Std", "Std"), state2 = c("Std", "Std"
+ ), type = c("null", "std"), parameter = c(1, 0), penalty = c(0, 
+                                                              0), K = c(Inf, Inf), a = c(0, 0), min = c(NA_real_, NA_real_), 
+ max = c(NA_real_, NA_real_), test = c(1, 2)), row.names = 1:2, class = c("data.frame"))
> test2 <- structure(list(state1 = c("Std", "Std"), state2 = c("Std", "Std"
+ ), type = c("null", "std"), parameter = c(1, 0), penalty = c(0, 
+                                                              0), K = c(Inf, Inf), a = c(0, 0), min = c(NA_real_, NA_real_), 
+ max = c(NA_real_, NA_real_), test = c(1, 2)), row.names = 1:2, class = c("data.frame", 
+                                                                          "graph"))
> test1
  state1 state2 type parameter penalty   K a min max test
1    Std    Std null         1       0 Inf 0  NA  NA    1
2    Std    Std  std         0       0 Inf 0  NA  NA    2
> test1 %>% select(state1)
  state1
1    Std
2    Std
> test2 %>% select(state2)
Error: `x` must be a vector, not a `data.frame/graph` object.
Run `rlang::last_error()` to see where the error occurred.

^^ the only difference there between test1 and test2 is whether it is of class "graph".

Although I am still perplexed that the reprex I put above worked on my local RStudio but broke on Travis and RStudio Cloud. So if anyone has any ideas/hints about why that would be, that would be great :smiley:

Second update: my local computer was on R 3.6.2. After updating to 4.0, I was able to get the correct error.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.