R言語学習ノートの

6447 ワード

Standaloneモード:Standaloneモードで実行されるSparkクラスタは、異なるアプリケーションに対して先進的なプリフェッチ(FIFO)の順序でスケジューリングされます.デフォルトでは、各アプリケーションは使用可能なノードのすべてのリソースを独占します.
現在のバージョンのSparkRはstandaloneモードでしか実行できません
問題1:インストールの問題
RはFortran言語にかかわるため、gcc-gfortranパッケージをダウンロードする
インストール手順:1)R-3.2.3.tar.gz解凍2)./configure 3)make 4)make install(このステップではなくてもよい)5)環境変数viを構成する.bash_profile 
./configureの場合、次のエラーが発生します.
--with-readline=yes(default)and headers/libs are not available readline-develパッケージに依存する必要があるためyum install readline-develでよい
configure:error:cannot compile a simple Fortran programこれはgcc-gfortranパッケージに依存する必要があるためyum install gcc-gfortranでよい
configure:error:--with-x=yes(default)and X 11 headers/libs are not available libXt-develパッケージに依存する必要があるためyum install libXt-develでよい
以上の手順は多くのパケットに依存している:①gcc②gcc-c+③readline-devel④gcc-gfortran⑤libXt-devel
yum install libXt-devel
yum install readline-devel
yum install gcc
yum install gcc-c++
yum install gcc-gfortran
tar -zxvf R-3.2.3.tar.gz
cd R-3.2.3
./configure
make

質問2:
unsupported URL scheme Warning: unable to access index for repository https://rweb.crmda.ku.edu/cran/src/contrib
ミラーリングの問題は、1)ミラーリングの変更、すなわち選択時に2)installを変更する2つの解決方法がある.packages("RODBC", dependencies = TRUE, repos = "http://cran.rstudio.com/")
質問3:Rパッケージのインストール中にエラーが発生しました
configure: error: "ODBC headers sql.hand sqlext.h not found"
Linuxの下にODBCパッケージがインストールされていないためです.RODBCはunixODBCとunixODBC developmentパッケージが必要で、YUMでインストールして解決します.
yum install unixODBC
yum install unixODBC-devel
後でpackages("RODBC", dependencies = TRUE, repos = "http://cran.rstudio.com/")
リモート・データベースに接続できないまま、ネットワークが通じないかどうかを確認するには、リモート・ホストをpingします.
SparkRプログラミングの例:
#       sparkR,     Sys.setenv .libPaths,  library(SparkR)  
#Sys.setenv(SPARK_HOME = "D:/StudySoftWare/Spark/spark-1.5.2-bin-hadoop2.6")
#.libPaths(c(file.path(Sys.getenv("SPARK_HOME"),"R","lib"), .libPaths()))
library(SparkR)
sc <- sparkR.init(master = "local")
#sc <- sparkR.init(master = "spark://192.168.133.11:7077")        
sqlContext <- sparkRSQL.init(sc)
DF <- createDataFrame(sqlContext, faithful)
head(DF)
localDF <- data.frame(name=c("John", "Smith", "Sarah"), age=c(19, 23, 18))
df <- createDataFrame(sqlContext, localDF)
# Print its schema
printSchema(df)
# root
#  |-- name: string (nullable = true)
#  |-- age: double (nullable = true)

# Create a DataFrame from a JSON file
path <- file.path(Sys.getenv("SPARK_HOME"), "examples/src/main/resources/people.json")
peopleDF <- jsonFile(sqlContext, path)
printSchema(peopleDF)

# Register this DataFrame as a table.
registerTempTable(peopleDF, "people")

# SQL statements can be run by using the sql methods provided by sqlContext
teenagers <- sql(sqlContext, "SELECT name FROM people WHERE age >= 13 AND age <= 19")

# Call collect to get a local data.frame
teenagersLocalDF <- collect(teenagers)

# Print the teenagers in our dataset 
print(teenagersLocalDF)

# Stop the SparkContext now
sparkR.stop()

java.io.IOException:Cannot run program"Rscript":error=2,No such file or directoryがこのエラーに遭遇したのは、次のためです.
looks like the issue was that code was looking for Rscript under "/usr/bin". Our default installation was/usr/revolutionr. Just created a link Rscript in/usr/bin that points to/usr/revolution/bin/Revoscript
または、Rscriptを/usr/binディレクトリにコピーします.参考:https://github.com/RevolutionAnalytics/RHadoop/issues/87
例2:wordCount
library(SparkR) 
sparkR.stop()  
#  sparkR            SparkContext,   local  
sc <- sparkR.init(master="spark://<pre name="code" class="plain">192.168.133.11
:7077","WordCount")#sparkR.init(master = "", appName = "SparkR",sparkHome = Sys.getenv("SPARK_HOME"), sparkEnvir = list(),sparkExecutorEnv = list(), s#parkJars = "", sparkPackages = "")
 
 
lines <- SparkR:::textFile(sc, "hdfs://namenode   /user/root/test/word.txt")
words <- SparkR:::flatMap(lines, function(line) { strsplit(line, " ")[[1]] })
wordCount <- SparkR:::lapply(words, function(word) { list(word, 1L) })
counts <- SparkR:::reduceByKey(wordCount, "+", 2L)
#      hdfs , path   "hdfs://namenode   /user/root/test/sparkR.txt") path      
SparkR:::saveAsTextFile(counts, "hdfs://namenode   /user/root/test/sparkR.txt")  
output <- SparkR:::collect(counts)

API documentation1:http://amplab-extras.github.io/SparkR-pkg/rdocs/1.2/index.html、このウェブサイトに与えられたAPIは、このように呼び出されます.
SparkR:::関数名
API documentation2:http://spark.apache.org/docs/1.5.2/api/R/index.html、このウェブサイトに与えられたAPIは、直接呼び出すことができる.