0
Follow
0
View

How to skip an error and in a for loop in R

donghee 注册会员
2023-01-25 22:52

We can create a function and then use tryCatch or possibly to skip the errors.

First create function f1 to get links to pictures,

#function f1
f1 = function(x){
  picture <- x %>% read_html() %>% html_element(".CmhTt") %>% html_attr("src")
}

apt <- pic_flat$apt_link

#now loop by skipping errors
pic = lapply(apt, possibly(f1, NA))

About the Author

Question Info

Publish Time
2023-01-25 22:52
Update Time
2023-01-25 22:52