Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 205423

[R6]Error in as.vector(x, "symbol") : cannot coerce type 'environment' to vector of type 'symbol'

$
0
0

I use my R6 object and funcion in the following code

Test = R6Class(
  "test",

  public = list(
    y_name = NA,

    initialize = function(y_name){
      self$y_name = y_name
    }

  )
)

someAnalysis = function(tbl, y_name = "y_name", y = "a", test = Test$new("y")){
   tbl = tbl %>%
    filter(!!as.name(y_name) == y)

   print(test$y_name)
   print(tbl$y_name)
}

In some case, it is done successfully.

someAnalysis(tbl)

[1] "y"
[1] "a"

However, the error occurs in the following code

test = Test$new("y")
someAnalysis(tbl, test)
Error in as.vector(x, "symbol") : 
  cannot coerce type 'environment' to vector of type 'symbol'

Why does error occur when defining the Test object outside of function?

Please tell me how to avoid error in using Test class and someAnalysis method


Viewing all articles
Browse latest Browse all 205423

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>