我想编写trycatch代码来处理从网上下载时的错误.
url <- c(
"http://stat.ethz.ch/R-manual/R-devel/library/base/html/connections.html",
"http://en.wikipedia.org/wiki/Xz")
y <- mapply(readLines, con=url)
Run Code Online (Sandbox Code Playgroud)
这两个语句成功运行.下面,我创建一个不存在的Web地址:
url <- c("xxxxx", "http://en.wikipedia.org/wiki/Xz")
Run Code Online (Sandbox Code Playgroud)
url[1]不存在.如何编写trycatch循环(函数)以便:
背景
我正在使用一个闪亮的应用程序cut和table一些数据。
数据集包含在shiny下面的代码中,但头部是:
> head(df_in)
Report_Year Position Target
1 2014 CEO 29.27644
2 2014 CEO 29.27644
3 2014 CFO 17.56586
4 2014 CE 17.56586
5 2014 COO 17.56586
6 2014 CEO 46.84231
Run Code Online (Sandbox Code Playgroud)
我正在使用以下语句cut和table数据
df <- df_in %>%
filter(Report_Year == input$v_year,
Position == "CEO") %>%
select(Target) %>%
filter(!is.na(Target)) %>%
mutate(bins = cut(Target, breaks=seq(0, (max(Target)+25), 25))) %>%
select(bins) %>%
table %>%
as.data.frame
>
. Freq
1 (0,25] 0
2 (25,50] 6
3 …Run Code Online (Sandbox Code Playgroud)