| S-PLUS 初學使用 (工作站版)
 S-PLUS 程式語言提供了一個互動式 (interactive)的程式環境, 
對於資料處理,
 統計分析和圖形展示具有強大的處理能力。本章旨在引導初學者了解一
 個 S-PLUS 程式作業的整個流程。
 
 
 一 進入&離開S-PLUS
 
 假使你是 rlogin 到別台機器,在進入 S-PLUS 
之前,請先設定顯示環境,
 這樣才能開視窗顯示圖形在你的螢幕上。
 [jasmine][~][1]> setenv DISPLAY 140.***.***.***:0.0
 
 140.***.***.*** 是你現在所在機器的ip.
 
 1. 進入S-PLUS: (要注意大小寫)
 
 [jasmine][~][1]> Splus 或
 [lily][~][1]> /SOFT/splus/Splus # Enter後,出現以下訊息
 S-PLUS : Copyright (c) 1988, 1995 MathSoft, Inc.
 S : Copyright AT&T.
 Version 3.3 Release 1 for Sun SPARC, SunOS 5.3 : 1995
 Working data will be in .Data
 
 > # S-PLUS 的 command 提示符號
 
 2. 離開S-PLUS
 在 S-PLUS 的提示符號鍵入q()即可離開 S-PLUS,回到 UNIX。
 
 
 二 編寫程式
 
 於S-PLUS 的提示符號鍵入
 > fix(testfile) # testfile 為程式名稱
 或
 > testfile <- vi(function(){}) # Enter之後,則會進入文字編輯器,如vi, 
joe...
 範例:
 function()
 {
 test <- c("this is a test file")
 print(test) # 印出字串
 openlook() # 使用繪圖指令前,須先下openlook()或 motif()
 par(mfrow=c(3,2)) # 同一頁放3*2個圖形
 x <- rnorm(50)
 hist(x,main="Example")
 }
 ~
 #是註解。
 
 編寫完,記得存檔並離開文字編輯器。(例如在vi的命令模式下,打 
:wq )
 此時程式若沒有語法上的錯誤,則僅出現提示符號 >.若有錯誤,則會
 有Error訊息,再鍵入fix()或fix(testfile)去修改程式,直到沒有
 錯誤為止。
 
 三 執行程式
 
 直接鍵入
 > testfile()
 [1] "this is a test file" # Output
 
 同時會出現一繪圖視窗,顯示所畫的圖,若此時有拼字上或其它的錯誤
 ,則會出現Error 訊息,再鍵入fix()或fix(testfile)去修改程式,直到
 沒有錯誤為止。
 
 想中斷程式的執行,按Ctrl+C。
 
 四 存檔
 
 1.程式及output部分
 > sink("homework1") # 準備存在檔名為homework1的檔案裡
 > testfile # 程式內容
 > testfile() # output
 > sink() # 結束存檔
 homework1 現已存在目前的目錄下了,可於UNIX下用vi或joe查看或修改。
 
 2. 圖形部分
 圖形可以直接列印,也可存在一個檔案裡,在此先說明
 如何存在一個檔案裡。 以openlook()為例,motif()的操作類同。
 在openlook視窗用滑鼠右鍵選Properties,再選Printing,此時會出現一個對話視窗。
 ,Method 選 PostScript。Orientation選項中的Landscape為橫印,Portrait
 為直印。在Command : 鍵入
 cat > plotname.ps <,再按Print即可
 將圖形存在plotname.ps的檔案裡。同時會產生
 ps.out.0001.ps的暫存檔,請把它刪除。
 
 五 列印
 
 1. 程式及output部分
 於UNIX下:
 >lpr -Psp1 homework1
 於S-PLUS中:
 >!lpr -Psp1 homework1
 2. 圖形部分
 直接列印 : 於openlook視窗中,以滑鼠右鍵選Graph的Print。
 (此時 Properties\Printing... \Command 為 lpr -h -r )
 
 從檔案列印 : 於 UNIX 中 ,鍵入 lpr -Psp1 plotname.ps。
    六 線上求助
 
 對於有疑問的函數或指令可以下列的方式查詢 :
 
 1. 文字介面help system
 
 > ?help # 查看更多有關help函數的資訊
 > help(func_name) # 顯示func_name這個函數或資料集的資訊
 > help("<-") # 特殊符號的help。 ex: <-, #,*...
 2. 圖形介面help system
 
 當然執行以下動作之前,須先設好顯示環境。
 > help.start(gui="openlook")
 或
 > help.start(gui="motif")
 或
 > options(gui="openlook")
 > helpstart()
 
 七 一些有關S Language的書籍
 
 1. S : an interactive environment for data analysis and graphics /Richard A. Becker, John 
M. Chambers.
 2. An introduction to S and S-plus / Phil Spector.(1994)
 3. The new S language : a programming environment for data analysis and graphics /
 Richard A. Becker, John M. Chambers, Allan R.Wilks.(1988)
 4. Statistical models in S / John M. Chambers, Trevor J. Hastie.(1992)
 5. Modern applied statistics with S-PLUS / W.N. Venables, B.D. Ripley.(1994)
 6. A handbook of statistical analyses using S-Plus / Brian S. Everitt. (1994)
 7. Introductory guide to S-PLUS. Unpublished manuscript. / Ripley, B.D.(1992)
 8. Notes on S-PLUS : A programming environment for data analysis and graphics.
 
 
    
 |