Error: no function to return from, jumping to top level

I have a condition when running code some times get the error Error: no function to return from, jumping to top level how can fit it?

if (Sys.time() %within% ## get time in day
    interval(Sys.Date() + hours(9),
             ## create an interval time
             Sys.Date() + hours(12) + minutes(31),
             tzone = "Iran")) {
    # saving the dataset ----
    write_csv(
        realtime_result,
        paste(
             "/media/fibunacci/New/bourse_bot1/log/full",date(),").csv",
            sep = ""
        )
    )
    
} else {
    return(NULL)
}

what are you expecting this to do that wouldnt happen if the whole else {} wasnt there at all ?

@nirgrahamuk I want use else for fuetre add item to it.
wirte else in after if condition but get error::
Error: unexpected '}' in "}"

return() only makes sense from within a function.
If you aren't in a function there is nothing to return from

yes,thanks @nirgrahamuk

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