RとWebサービス


RSOAP†

RSOAP とは†

 元々はZopeで利用するR用のSOAPインターフェースあったが、SOAP をサポートするアプリであれば利用できる。。PythonとRとのインターフェースである Rpy と、PythonでSOAPサービスを提供するSOAPpy を併用することで、RをSOAPから利用できるようにしている。

インストール†

必要なソフトウェア†

以下は RSOAP 1.1.4 の場合

インストール†

実行†

利用方法†

RSOAPは、「サーバマネージャ」サービスと「サーバプロセス」サービスの2種類からなり、まず「サーバマネージャ」サービスに接続し、そのnewServerメソッドを呼んで「サーバプロセス」サービスのURLを得る。その後「サーバプロセス」サービスに接続し、主にcall, evalメソッドを用いて解析を実行する。

利用例†

MacOS X のAppleScriptから呼んだ例†

-- サーバマネージャサービスのURLがlocalhost:9081のとき
tell application "http://localhost:9081/"
      set returnValue to call soap {method name:"newServer", ¬
         method namespace uri:"", parameters:"", SOAPAction:""}
end tell
-- 上の呼び出しで、たとえば"http://localhost:9087"が返ってきたとき
tell application "http://localhost:9087/"
      set returnValue to call soap {method name:"call", ¬
         method namespace uri:"", parameters:{|String|:"rnorm", |aNumber|:10}, SOAPAction:""}
end tell

WSDLの書き方例†

eval, downloadFileだけが使えるサンプル(「サーバプロセス」サービス)

 <?xml version="1.0"?>
 <definitions name="RSOAP" targetNamespace="urn:RSOAP"
     xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
     xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
     xmlns:xsd="http://www.w3.org/1999/XMLSchema" 
     xmlns:rsoap="urn:RSOAP" xmlns="http://schemas.xmlsoap.org/wsdl/" >
   <types>
     <xsd:complexType name="downloadFileResponseType">
         <xsd:all>
           <xsd:element name="flag" type="xsd:int"/>
           <xsd:element name="data" type="xsd:string"/>
         </xsd:all>
     </xsd:complexType>
   </types>
 <message name="downloadFileRequest">
   <part name="name" type="xsd:string"/>
 </message>
 <message name="downloadFileResponse">
       <part name="response" type="rsoap:downloadFileResponseType"/>
 </message>
 <message name="evalRequest">
   <part name="string" type="xsd:string"/>
 </message>
 <message name="evalResponse">
   <part name="value" type="xsd:string"/>
 </message>
 <portType name="RSOAPProcess">
   <operation name="eval">
     <input message="rsoap:evalRequest"/> <output
                                             message="rsoap:evalResponse"/>
   </operation> 
    <operation name="downloadFile">
     <input message="rsoap:downloadFileRequest"/> <output
                                             message="rsoap:downloadFileResponse"/>
   </operation>
 <service name="RSOAPProcessService">
   <documentation>RSOAP Process API Service</documentation>
   <port name="RSOAPProcessPort" binding="rsoap:RSOAPProcessSoapBinding">
     <soap:address
        location="http://localhost:9083"/>
   </port>
 </service>
<binding name="RSOAPProcessSoapBinding" type="rsoap:RSOAPProcess">
   <soap:binding style="document"
                 transport="http://schemas.xmlsoap.org/soap/http"/>
   <operation name="eval">
     <soap:operation
        soapAction="" style="rpc"/>
     <input>
       <soap:body use="literal"
                  />
     </input>
     <output>
       <soap:body use="literal"
                  />
     </output>
   </operation>
   <operation name="downloadFile">
     <soap:operation
        soapAction="" style="rpc"/>
     <input>
       <soap:body use="literal"
                  />
     </input>
     <output>
       <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 
             namespace="urn:RSOAP" use="encoded"/>
                  />
     </output>
   </operation>
 </binding>
 </definitions>

WebObjectsから呼んでみる†

(工事中)

注意事項†

RSOAPは比較的古いSOAP実装であるSOAPpyを使っているため、SOAPメッセージの出力時にXML schemaのバージョンが1999となっている。したがって配列型を返す場合にその型が2001バージョンのanyTypeではなく, ur-typeとなっているので、新しいSOAPクライアント(apache axis, .NETなど)から接続する場合にそのままでは配列型のデータを交換できない。

ただし、SOAPpyをちょっと改造してur-typeと出力しているところをanyTypeに単純置換するだけでも実用上はわりと問題なかったりする。

利用例†

 データマイニングソフトSpotfire*1でRのクラスタリング機能の呼び出しなどに利用されている。事例1。事例2。事例3。

関連リンク†

Rterm や Rscriptとの併用例。Rscript は不等号や ^ がそのまま利用できる。†

プログラム例(Rscript†

$RPath  = 'C:\\R\\R-2.9.1\\bin\\Rscript.exe';  // Your R path here

$dbfPathName = "/temp/test.dbf";
$cmd = $RPath." -e \"library(foreign);d=read.dbf('$dbfPathName');mean(d['POP'])\""; 
$res = shell_exec($cmd);//R の実行
echo explode(" ", $res);//行番号を取る

プログラム例(Rterm)†

$RPath  = 'C:\\R\\R-2.9.1\\bin\\Rterm.exe';  // Your R path here

$dbfPathName = "/temp/test.dbf";
$cmd = "echo library(foreign);d=read.dbf('$dbfPathName');mean(d['POP'])| $RPath --slave"; 
$res = shell_exec($cmd);//R の実行。injectgion 対策が要る。
echo explode(" ", $res);//行番号を取る

PHP†

R_PHP

またこのままだとクオーテーションがバックスラッシュつきなので

Rserve の次期バージョンに簡単な PHP クライアントが付属する予定†

Python†

JSON†

GeoJSON†

 地理空間データ用JSON

Google†

Google Docs†

Google Trends†

Google Maps†

Google Earth†

Google Chart Tools†

Google Visualization API†

Google Spreadsheets†

Google Fusion Tables†

Google JSON†

=gooJSON

BigQuery†

Google Prediction API†

Google Scholar†

Google Weather API†

Google Analytics†

Twitter†

twitteR: R ベースの Twitter クライアント†

 Twitter API を利用

短縮URLのデコード†

RWebServices:Expose R functions as web services through Java/Axis/Apache†

SSSR: Server Side Scripting with R†

Amazon†

RAmazonS3 S3 アマゾンストレッジサーバー用インターフェース†

RAmazonDBREST Amazon's Simple DB API 用 REST インターフェース†

Flickr†

Rflickr R より 113 個の API 関数の呼び出し可能。†

New York Times†

RNYTimes New York Times ウェブサービスの内のいくつかのもの(記事の検索、メタデータ、ユーザ作成コンテンツ、ベストセラーリスト)へのインターフェースを提供。†

Last.fm†

RLastFM: R interface to last.fm API last.fm API インターフェース

Zillow 不動産情報†

GIS 関連†

Geo API†

地名†

RCurl†

REST サービスのサンプルコード

nytR: Provides access to the NY Times API†

現状はアメリカ議会情報のデータ

世界銀行†

参考リンク†

他言語からR利用(インチキ版) awk からの利用方法†

R で GeoWeb†

Wolfram|Alpha API.†

Facebook†

Facebook Graph API†

Sensor Observation Services (SOS)†

Soil Web†

Yahoo!†

Yahoo! JAPANが提供するテキスト解析Web API†

GeoRSS†

Foursquare†

東京電力†

RとWeb API†

Groupon†

Bing†

Bing Maps†

Weather API†

Dropbox†

Capitol Words API†

Global Biodiversity Information Facility†

SMS analysis (coming from an Android smartphone or an IPhone) ウェブサービスではないが参考まで†

次世代統計利用システム†


*1 CIA 関連会社が設立に関与。Google が SketchUp に次いで買収を狙っているという話もある。

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2023-03-25 (土) 11:19:17