how to know the surv function execution is done

Hi Everybody,

I am very new to R.

I was wondering how I can know if the execution of the Surv function is done.

Apologize if this has been discussed before. If it was discussed before can anyone point me to the original posting?

Thanks in advance.

While an R function is running, it shows no > prompt in the console pane until it is finished. Unless dealing with large data it is rare for a function to make very many seconds. For example,

with(aml, Surv(time, status))
#>  [1]   9   13   13+  18   23   28+  31   34   45+  48  161+   5    5    8    8 
#> [16]  12   16+  23   27   30   33   43   45
survfit(Surv(time, status) ~ ph.ecog, data=lung)
#> Call: survfit(formula = Surv(time, status) ~ ph.ecog, data = lung)
#>    1 observation deleted due to missingness 
#>             n events median 0.95LCL 0.95UCL
#> ph.ecog=0  63     37    394     348     574
#> ph.ecog=1 113     82    306     268     429
#> ph.ecog=2  50     44    199     156     288
#> ph.ecog=3   1      1    118      NA      NA

microbenchmark(Surv(heart$start, heart$stop, heart$event))
#> Unit: microseconds
#>                                        expr    min      lq     mean median
#>  Surv(heart$start, heart$stop, heart$event) 30.904 31.8745 36.24839 32.288
#>      uq     max neval
#>  32.825 357.342   100

Thank you for your reply.

I see the > instantly after i hit enter for the call of the Surv function. but i did not get any output file. Does this mean this function does not produce any output file?

Can you please further advise?


To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

In the example above

without running the time, so

Surv(heart$start, heart$stop, heart$event)

returns its value to the screen, but it does not persist unless assigned its own object name

my_result <- Surv(heart$start, heart$stop, heart$event)


Thank you for guiding me.

I tried to produce a sample dataset but i got errors.

I was wondering if you can tell i should get an output or an output file if i run the below command (i have successfully created the data frame and those two variables are in the dataset)
S <- (Surv(data$Time_fup, data$outc_diab)

Please advise.

Did you try just calling S?

yes . i did. but i got errors. 

model <- psm(S ~ data$Immigration + data$Ethnics + data$Csection + data$Diab_preg + data$Htn_PreEcl + data$incquint + data$age_deli + data$Inf_weight2 + data$Gest_wks + data$BMI + data$Glucose, X=TRUE, Y=TRUE)
Error in if (!length(fname) || !any(fname == zname)) { :
missing value where TRUE/FALSE needed

This illustrates the difficulty that the lack of a reprex causes. See the FAQ: How to do a minimal reproducible example reprex for beginners as @nirgrahamuk brought up.

There is now a new function psm() from a different package, {rms} working with data that can only be guessed out and it's still not apparent whether or not S is working yet. The problem may be as the package author explained:

Use data=. Don't use $ in variables in the model.


Thank you for your further guidance.

It is not easy for me to produce the sample data.

I tried the Surv function again. If I do not assign the function call to S I can see the output. But it is odd that the assignment does not work. I am using the IT built Rstudio through Xterm and it was not the regular Rstudio server.

Can you tell if the way that I access to Rstudio may lead to the errors I got or anything wrong?

Thanks again.

do you have evidence of assignment 'not working'.
by not working do you simply mean, not also printing out ?

No. I do not have evidence it does not work. But my understanding is if it works it should output to the console.

Yes. Not working for me means not printing out. I do see S in the environment pane. But it only shows the file size and attributes information. I need to see the output that I got for not performing the assignment.

Please point out if I have missed important information or if I have misunderstood anything.

If a function returns an object with a print method (most do, including Surv()), then simply typing the object S at a prompt in the console will provide a display. On the other hand, most functions simply discard objects they complete and you have to expressly assign it from outside the function.

my_new_object <- my_function(x, this, that, other)

As far as the RStudio installation, I always assume that if an IT department doesn't use software for its own internal purposes, it's not always installed and maintained with care unless someone very senior in the organization is asking.

There's an alternative, assuming that IT hasn't also locked down interactive websites: Posit Cloud, which provides a web interface to the RStudio GUI that is almost identical to what you experience on the desktop.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.