ggobi / tourr

A implementation of tour algorithms in R
http://ggobi.github.io/tourr/
Other
65 stars 21 forks source link

guided_tour #108

Closed z267xu closed 1 year ago

z267xu commented 3 years ago

Dear maintainer I recently built a package based on tourr. After I update tourr to 0.6.0, the guided_tour does not work anymore. I checked my code, I think the reason comes from here:

> tour_path = tourr::guided_tour(tourr::holes())
> tour_path(NULL, iris[, -5])
Error: New rows can't add columns.
x Can't find columns `basis`, `index_val`, `info`, `method`, `alpha`, and 2 more in `.data`.

The reason may come from this line

rcd_env <- parent.frame(n = 3)
rcd_env[["record"]] <- dplyr::add_row(rcd_env[["record"]], 
    basis = list(current), index_val = cur_index, info = "new_basis", 
    method = method, alpha = formals(guided_tour)$alpha, tries = 1, 
    loop = 1)

If I call tour_path(NULL, iris[, -5]) in the global environment, rcd_env seems fail to locate the env.

huizezhang-sherry commented 3 years ago

Hi! The documentation in the last commit da665aea43f2e321e5a31313d87b6d31abe58619 could be useful for your problem. Let me know if the problem still persists.

z267xu commented 3 years ago

Hi Sherry Thanks! It works. However, I think this could not be a good idea to ask users to define a variable ahead in the environment... I would suggest the code look into it, if record is not found, then create one and leave a message, for example

tryCatch(expr = {
  rcd_env <- parent.frame(n = 3)
  rcd_env[["record"]] <- dplyr::add_row(rcd_env[["record"]], 
     basis = list(current), index_val = cur_index, info = "new_basis", 
     method = method, alpha = formals(guided_tour)$alpha, tries = 1, 
     loop = 1)
}, error = function(e) {
  # record is not defined in `parent.frame()`
  # leave a message or something else
  assign("record", record <- dplyr::tibble(basis = list(),index_val = numeric(), info = character(), method = character(), alpha = 
  numeric(), tries = numeric(), loop = numeric()), env ...)
  rcd_env[["record"]] <- dplyr::tibble(basis = list(current), index_val = cur_index, info = "new_basis", 
               method = method, alpha = formals(guided_tour)$alpha, 
               tries = 1, loop = 1)
})

It is just an idea came to my mind. There should be some more elegant way to make it work