-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
why ggsurvplot can not be called in function frame #288
Comments
Hi, when using ggsurvplot, you should always specify the argument data. In your case, specifying data = df2, should fix the issue |
Soga.
thanks.
来自 魅族 PRO 6s
…-------- 原始邮件 --------
发件人:Alboukadel KASSAMBARA <notifications@github.com>
时间:周四 2月1日 21:21
收件人:kassambara/survminer <survminer@noreply.github.com>
抄送:王诗翔 <wangshx@shanghaitech.edu.cn>,Author <author@noreply.github.com>
主题:Re: [kassambara/survminer] why ggsurvplot can not be called in function frame (#288)
Hi, when using ggsurvplot, you should always specify the argument data. In your case, specifying data = df2, should fix the issue
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<#288 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AX5Y5K0FQrO6Ll-tUchhSpl6p67UNmBRks5tQbmqgaJpZM4R1lTp>.
|
Hello, I used following coding to test [df2.zip] load("./df2.Rdata")
test_fun <- function(df2){
sfit <- survfit(Surv(df2[,"OS"], df2[, "OS_IND"])~group, data=df2)
ggsurvplot(sfit, data=df2)
}
df1 <- df2; rm(df2)
test_fun(df2=df1) the error is still
I try debug function as deep as I can, and find in Browse[8]> stats::get_all_vars(.formula, data = data)
Error in eval(inp, data, env) : object 'df2' not found
Browse[8]> .formula
Surv(df2[, "OS"], df2[, "OS_IND"]) ~ df2$group
<environment: 0x000000001ad19d48> I already know what is wrong, if I change test_fun <- function(df2){
sfit <- survfit(Surv(OS, OS_IND)~group, data=df2)
ggsurvplot(sfit, data=df2)
} But I cannot do this because I want to write a function which I do not know which variable is mapping to I tried to use test_fun <- function(df2, time="OS", event="OS_IND"){
sfit <- survfit(Surv(as.symbol(time), as.symbol(event))~group, data=df2)
ggsurvplot(sfit, data=df2)
} but >test_fun(df2=df1)
Show Traceback
Rerun with Debug
Error in Surv(as.symbol(time), as.symbol(event)) :
Time variable is not numeric I use colnames(df2)[colnames(df2) == time] <- "time"
colnames(df2)[colnames(df2) == event] <- "event"
sfit <- survfit(Surv(time, event) ~ group, data=df2) to fix this. It is strange that I cannot use sfit <- survfit(as.formula(paste0("Surv(", time, ",", event, ") ~ group")), data=df2) or .formula <- as.formula(paste0("Surv(", time, ",", event, ") ~ group"))
sfit <- survfit(.formula, data=df2 I know little about advanced R. Can you give me a suggestion to set a right |
you should declare the "df2" in global env like |
I second this issue, I don't think it makes sense that a function argument to ggsurvplot has to be declared in the global environment. This seems (IMHO), with all due respect, not perfectly in line with the expected R scoping rules. |
Expected behavior
I wanna call
ggsurvplot
function instead of defaultplot
function in my custom functionActual behavior
A error occur.
Steps to reproduce the problem
I debug my function and find something wrong when call
ggsurvplot
.I store my dataset used to call
ggsurvplot
df2.zip
I reduce anything else not with this problem and create a minimal function, find the same problem.
But it is very strange that I can use
eval(fit$call$data)
inside the function.I directly use
ggsurvplot
in global environment, it works well.I try put
df2
in global environment, it works well, and if I change the value ofdf2
, error occur.I figure it out that
ggsurvplot
function will retrieve origin data.frame in global environment instead of current frame, can you fix it?session_info()
The text was updated successfully, but these errors were encountered: