R語言環境變量的設置 環境設置函數爲options()

環境設置函數爲options(),用options()命令能夠設置一些環境變量,使用help(options)能夠查看詳細的參數信息。

1. 數字位數的設置,options(digits=n),n通常默認狀況下是7位,但實際上的範圍是1~22,能夠隨意設置位數。

#這個命令,能夠把R的整數表示能力設爲10位。 options(digits=10)

2. 擴展包的安裝,使用下面的命令,能夠聯網安裝擴展包。

options(CRAN="http://cran.r-project.org") install.packages("擴展包名")

3. 利用R裏的options函數進行光標和數字位數設置。

用R寫代碼時,打字水平不高,有時候不知道亂按了一些鍵(如今我還不知道哪一個鍵),光標就變成了加粗的豎直線,又改不回去。這種狀況下咱們能夠用options函數進行光標設置,例如:html

##能夠隨意設置你的光標類型(prompt參數設置)。 ##光標開始默認爲 > options(prompt="|") ##光標爲 | options(prompt=">") ##光標爲 > options(prompt="|") ##光標爲 | options(prompt="+") ##光標爲 + options(prompt="-") ##光標爲 - options(prompt="8") ##光標爲 8 options(prompt=">") ##光標設置爲開始默認值 >

4. R裏的options函數進行錯誤信息顯示(忽略)設置。

#這個命令,能夠忽視任何警告 options(warn=-1) #這個命令,不放過任何警告 options(warn=1) #示例展現 ow <- options("warn") for(w in -1:1) { options(warn = w); cat("\n warn =", w, "\n") for(i in 1:4) { cat(i,"..\n"); m <- matrix(1:7, 3,4) } } warnings() options(ow) # reset tail(warnings(), 2) #說明: warn: sets the handling of warning messages. If warn is negative all warnings are ignored. If warn is zero (the default) warnings are stored until the top–level function returns. If 10 or fewer warnings were signalled they will be printed otherwise a message saying how many were signalled. An object called last.warning is created and can be printed through the function warnings. If warn is one, warnings are printed as they occur. If warn is two or larger all warnings are turned into errors. ------- 警告: 設置警告消息的處理。若是警告是負面的,全部的警告都會被忽略。若是警告是零(默認)警告被存儲到頂部,級別的函數返回。若是10個或更少的警告信號,他們將被打印出來,不然一個消息說有多少人發出信號。一個對象稱爲last.warning能夠經過打印功能warnings。若是警告是一個,警告是印刷的,由於它們發生。若是警告是2或更大的全部警告被變成錯誤。 ##還能夠width來調整向量,矩陣的輸出寬度,還包括是否用warnning來顯示錯誤信息(show.error.messages)以及錯誤信息的長度(warning.length)。 options(show.error.locations = TRUE) options("show.error.messages")

5. options()經常使用於設置R控制檯、R語言計算相關的屬性,經常使用屬性名稱及默認值以下:

add.smooth TRUE
check.bounds FALSE continue "+ " digits 7 echo TRUE encoding "native.enc" error NULL expressions 5000 keep.source interactive() keep.source.pkgs FALSE max.print 99999 OutDec "." prompt "> " scipen 0 show.error.messages TRUE timeout 60 verbose FALSE warn 0 warning.length 1000 width 80 #裝載不一樣的擴展包還會增長一些新的屬性信息

6. 設置環境變量R_LIBS將R包安裝到自定義路徑

關於R啓動(help(Startup))和選項(help(options))的內容,參見R幫助頁面。

相關文章
相關標籤/搜索