Closed spgarbet closed 4 years ago
@sbalci
The issue you're having is caused by hmisc being assumed to be in the global context. In jamovi it's not. I need to understand the environment contexts in jamovi and the way libraries / code are handled, and more about this error. What tangram is allowing the user to do is override in their global enviroment style definitions and these are used in preference to the ones in the library itself. jamovi is doing something a little different with environments.
So there are two issues here. The first I can fix easily, in that if the "get()" call fails it keeps executing to it's fall back. So a try block is needed. But in jamovi this will not result in the intended behavior.
If I put this R code into jamovi:
x <- 3 get("x", envir = globalenv())
Does this fail? If not, then if the 'get' call is inside a library it would fail. Can you describe how the environments are loaded?
I tried to get jamovi installed on Ubuntu 20 and I couldn't get that to work because of flatpak. They have a ticket open discussing that issue.
Hi,
I get following error when using tangram@0.3.2
Debug
Error in get("x", envir = globalenv()): 'x' nesnesi bulunamadı
private$.run()
get("x", envir = globalenv())
The tangram function works as expected when using tangram@0.3.2
see below gif:
The request for "x" has nothing to do with tangram, but how environments are structured inside jamovi.
tangram needs to be able to find the variable that defines the styles. That variable could be in the user's current environment.
x <- 3
creates a variable in the current environment in R.
get("x", envir=globalenv())
Is a meta call that says, give me the object named "x", start in the current environment and search all parents up to the global env.
Normally if tangram is loaded, it pulls from that environment. Otherwise it pulls from the local environment. I can force it to load from the package environment as a fall back. If a user copies that 'hmisc' variable and overrides it's style functions then it will not be found. So to fix this properly I need to understand what jamovi is doing with environments. Why does the "get" call fail?
https://www.r-bloggers.com/environments-in-r/
What does this print out (no libraries loaded)
g <- globalenv()
while (environmentName(g) != 'R_EmptyEnv') {
g <- parent.env(g); cat(str(g, give.attr=F))
}
Actually, here's a better thing to try (no libraries)
x <- 3
get("x", inherits=TRUE)
Hi, Thank you for your time.
I import the tangram function to the package: https://github.com/sbalci/ClinicoPath/blob/668b7c2e7ecd28e2e3b5b2885679085d7571ee58/R/crosstable.b.R#L9
As a side note, I also had a similar issue with ggalluvial
and adding StatStratum <- ggalluvial::StatStratum
to function it resolved.
When I try
x <- 3
get("x", inherits=TRUE)
it returns the value:
[1] 3
g <- globalenv()
while (environmentName(g) != 'R_EmptyEnv') {
g <- parent.env(g); cat(str(g, give.attr=F))
}
I get no result. Probably stuck in while loop??
Best wishes
I think I understand now. I will have a fix that requires some testing.
Is it possible for you to pull the github version and test?
Hi, I get following error:
Debug
Error in get(style, envir = globalenv()): 'hmisc' nesnesi bulunamadı
private$.run()
tangram::html5(tangram::tangram(formula, self$data), fragment = TRUE, inline = style, caption = paste0("Cross Table for Dependent ", self$options$group), id = "tbl3")
tangram::tangram(formula, self$data)
tangram.formula(formula, self$data)
tryCatch(get(style, envir = globalenv()), finally = get(style))
tryCatchList(expr, classes, parentenv, handlers)
get(style, envir = globalenv())
I will get the hang of this yet. I pushed a new patch that might fix it.
Hi, Thank you very much for your efforts. I think the hmisc issue is resolved 👍
Although now I get attempt to apply non-function
error.
I assume I am having problem in converting inputs into a formula (A~ B +C). I am trying to get over it.
Debug
Error in value[[3L]](cond): fonksiyon olmayana uygulama denemesi
private$.run()
tangram::html5(tangram::tangram(formula, self$data), fragment = TRUE, inline = self$options$sty, caption = paste0("Cross Table for Dependent ", self$options$group), id = "tbl3")
tangram::tangram(formula, self$data)
tangram.formula(formula, self$data)
tryCatch(get(style, envir = globalenv()), error = get(style))
tryCatchList(expr, classes, parentenv, handlers)
tryCatchOne(expr, names, parentenv, handlers[[1]])
Change the call to the following:
tangram::html5(tangram::tangram(formula, self$data), style="hmisc", caption = paste0("Cross Table for Dependent ", self$options$group), id = "tbl3")
Did that work?
I am trying with iris now.
Code works in R. But when I call it within jamovi I get following error attempt to apply non-function
Debug
Error in value[[3L]](cond): fonksiyon olmayana uygulama denemesi
private$.run()
tangram::tangram("Species ~ Sepal.Length + Sepal.Width + Petal.Length", iris, style = "nejm", caption = paste0("Cross Table for Dependent "), id = "tbl3")
tangram.character("Species ~ Sepal.Length + Sepal.Width + Petal.Length", iris, style = "nejm", caption = paste0("Cross Table for Dependent "), id = "tbl3")
tangram.formula(trimws(x), ...)
tryCatch(get(style, envir = globalenv()), error = get(style))
tryCatchList(expr, classes, parentenv, handlers)
tryCatchOne(expr, names, parentenv, handlers[[1]])
Just saw this. There's one more thing I can try.
I've changed this to getAnywhere which searches all loaded environments.
Hi @spgarbet, Thank you for your time.
This one works in R but inside jamovi I am still getting the same attempt to apply non-function
error.
I am trying to figure out why.
I tried to call tangram::tangram
or tangram:::tangram.formula
inside jamovi it returns the function texts correctly.
So is the problem in calling from environment or recognizing the text as formula?
What is Error in value[[3L]](cond)
error?
There is an R meta call, get. This is used to get the style from a string. Local environment overrides package environment. I don't know what that error is. I have a windows loaner box I will play with on this.
I have it installed on a Windows box. I can't figure out how to get at executing R code inside Jamovi. What are the steps to debug/triage this in the Jamovi environment?
Details are here: https://dev.jamovi.org/ Briefly:
Use R 3.6.3
Install jamovi from this link: https://www.jamovi.org/download.html Get the latest one 1.2.19
Install jmvtools package with: install.packages('jmvtools', repos=c('https://repo.jamovi.org', 'https://cran.r-project.org'))
locate jamovi bin folder via this: jmvtools::check("C://Program Files//jamovi//bin")
I recommend changing folder name from default jamovi 1.2
to jamovi
Fork and Clone this repo: https://github.com/sbalci/ClinicoPath
inside this repo folder in R jmvtools::install()
it will produce a file named ClinicoPath.jmo and install this module to jamovi
The repo is like an R package except jamovi
folder.
You need to edit R/crosstable.b.R
Just edit the tangram::
code
https://dev.jamovi.org/tuts0104-implementing-an-analysis.html
https://dev.jamovi.org/tuts0105-debugging-an-analysis.html
In DESCRIPTION file change spgarbet/tangram@0.3.2
to the version you want to test.
run jmvtools::install()
again.
Let me know how it goes :)
jmvtools::check("C://Program Files//jamovi//bin")
jamovi compiler
jamovi 1.2.19 found at C:\Program Files\jamovi\bin\jamovi.exe
jmvtools::install()
jamovi compiler
jamovi could not be found!
Please try this:
jmvtools::install(home = "C://Program Files//jamovi//bin")
I got the compile working, still working through the developer material for Jamovi.
I tried just R6 to see if that was the issue it was not. I think I have a workaround that would extend the functionality of the whole package. I'm still working on understanding how Jamovi modules compile.
Try this:
tangram( ..., transform=tangram::hmisc, ...)
Hi, It seems to work. This is the code:
tabletangram <-
tangram::html5(
tangram::tangram(
formula,
mydata,
transform=tangram::hmisc
),
fragment = TRUE,
# inline = sty,
caption = paste0(
"Cross Table for Dependent ",
self$options$group),
id = "tbl3")
And this is the output:
Excellent. I can close this now.
See tail of issue #38.