それでは、Rの世界へようこそ;-) 
どうぞ
コードを設定する
urls <- c(
    "http://stat.ethz.ch/R-manual/R-devel/library/base/html/connections.html",
    "http://en.wikipedia.org/wiki/Xz",
    "xxxxx"
)
readUrl <- function(url) {
    out <- tryCatch(
        {
            # Just to highlight: if you want to use more than one 
            # R expression in the "try" part then you'll have to 
            # use curly brackets.
            # 'tryCatch()' will return the last evaluated expression 
            # in case the "try" part was completed successfully
            message("This is the 'try' part")
            readLines(con=url, warn=FALSE) 
            # The return value of `readLines()` is the actual value 
            # that will be returned in case there is no condition 
            # (e.g. warning or error). 
            # You don't need to state the return value via `return()` as code 
            # in the "try" part is not wrapped insided a function (unlike that
            # for the condition handlers for warnings and error below)
        },
        error=function(cond) {
            message(paste("URL does not seem to exist:", url))
            message("Here's the original error message:")
            message(cond)
            # Choose a return value in case of error
            return(NA)
        },
        warning=function(cond) {
            message(paste("URL caused a warning:", url))
            message("Here's the original warning message:")
            message(cond)
            # Choose a return value in case of warning
            return(NULL)
        },
        finally={
        # NOTE:
        # Here goes everything that should be executed at the end,
        # regardless of success or error.
        # If you want more than one expression to be executed, then you 
        # need to wrap them in curly brackets ({...}); otherwise you could
        # just have written 'finally=<expression>' 
            message(paste("Processed URL:", url))
            message("Some other message at the end")
        }
    )    
    return(out)
}
コードを適用する
> y <- lapply(urls, readUrl)
Processed URL: http://stat.ethz.ch/R-manual/R-devel/library/base/html/connections.html
Some other message at the end
Processed URL: http://en.wikipedia.org/wiki/Xz
Some other message at the end
URL does not seem to exist: xxxxx
Here's the original error message:
cannot open the connection
Processed URL: xxxxx
Some other message at the end
Warning message:
In file(con, "r") : cannot open file 'xxxxx': No such file or directory
出力の調査
> head(y[[1]])
[1] "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"      
[2] "<html><head><title>R: Functions to Manipulate Connections</title>"      
[3] "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"
[4] "<link rel=\"stylesheet\" type=\"text/css\" href=\"R.css\">"             
[5] "</head><body>"                                                          
[6] ""    
> length(y)
[1] 3
> y[[3]]
[1] NA
追加備考
tryCatch
tryCatchexprエラーや警告がない限り、実行に関連付けられた値を返します。この場合、特定の戻り値(return(NA)上記を参照)は、それぞれのハンドラー関数(引数errorとwarningを参照)を提供することによって指定できます?tryCatch。これらは既に存在する関数にすることもできますが、tryCatch()(上記で行ったように)内部で定義することもできます。
ハンドラー関数の特定の戻り値を選択することの意味
NAエラーの場合に返されるように指定したので、の3番目の要素はyですNA。我々が選択した希望の場合NULL、戻り値になるように、長さはyちょうどだっただろう2の代わり3として、lapply()単にある戻り値を「無視」の意志NULL。また、を介して明示的な戻り値を指定しない場合return()、ハンドラー関数が戻りますNULL(つまり、エラーまたは警告状態の場合)。
「望ましくない」警告メッセージ 
warn=FALSEどんな効果があるとは思えない、(この場合は本当に興味のない)警告を抑制するための別の方法は使用することです
suppressWarnings(readLines(con=url))
の代わりに 
readLines(con=url, warn=FALSE)
複数の表現
あなたも(引数「実際の表現の一部」で複数の式を置くことができることを注意exprのtryCatch()あなたは(私はに示されているだけのように中括弧でそれらをラップしている場合)finallyの部分)。
               
              
paste関数の最初の文字列がスペースで終わっているとすると、スペースとsep=""?