Skip to content

Commit 6c42fdc

Browse files
committed
Remove SparkR RDD examples, add dataframe examples
1 parent 845d1d4 commit 6c42fdc

File tree

8 files changed

+55
-355
lines changed

8 files changed

+55
-355
lines changed

R/pkg/NAMESPACE

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ exportMethods("cache",
4545
"showDF",
4646
"sortDF",
4747
"take",
48-
"toJSON",
49-
"toRDD",
5048
"unionAll",
5149
"unpersist",
5250
"where",
@@ -95,14 +93,12 @@ export("cacheTable",
9593
"createExternalTable",
9694
"dropTempTable",
9795
"jsonFile",
98-
"jsonRDD",
9996
"loadDF",
10097
"parquetFile",
10198
"sql",
10299
"table",
103100
"tableNames",
104101
"tables",
105-
"toDF",
106102
"uncacheTable")
107103

108104
export("sparkRSQL.init",

R/pkg/R/DataFrame.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ setMethod("names",
272272
setMethod("registerTempTable",
273273
signature(x = "DataFrame", tableName = "character"),
274274
function(x, tableName) {
275-
callJMethod(x@sdf, "registerTempTable", tableName)
275+
invisible(callJMethod(x@sdf, "registerTempTable", tableName))
276276
})
277277

278278
#' insertInto

examples/src/main/r/dataframe.R

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
library(SparkR)
19+
20+
# Initialize SparkContext and SQLContext
21+
sc <- sparkR.init(appName="SparkR-DataFrame-example")
22+
sqlContext <- sparkRSQL.init(sc)
23+
24+
# Create a simple local data.frame
25+
localDF <- data.frame(name=c("John", "Smith", "Sarah"), age=c(19, 23, 18))
26+
27+
# Convert local data frame to a SparkR DataFrame
28+
df <- createDataFrame(sqlContext, localDF)
29+
30+
# Print its schema
31+
printSchema(df)
32+
# root
33+
# |-- name: string (nullable = true)
34+
# |-- age: double (nullable = true)
35+
36+
# Create a DataFrame from a JSON file
37+
path <- file.path(Sys.getenv("SPARK_HOME"), "examples/src/main/resources/people.json")
38+
peopleDF <- jsonFile(sqlContext, path)
39+
printSchema(peopleDF)
40+
41+
# Register this DataFrame as a table.
42+
registerTempTable(peopleDF, "people")
43+
44+
# SQL statements can be run by using the sql methods provided by sqlContext
45+
teenagers <- sql(sqlContext, "SELECT name FROM people WHERE age >= 13 AND age <= 19")
46+
47+
# Call collect to get a local data.frame
48+
teenagersLocalDF <- collect(teenagers)
49+
50+
# Print the teenagers in our dataset
51+
print(teenagersLocalDF)
52+
53+
# Stop the SparkContext now
54+
sparkR.stop()

examples/src/main/r/kmeans.R

Lines changed: 0 additions & 93 deletions
This file was deleted.

examples/src/main/r/linear_solver_mnist.R

Lines changed: 0 additions & 107 deletions
This file was deleted.

examples/src/main/r/logistic_regression.R

Lines changed: 0 additions & 62 deletions
This file was deleted.

examples/src/main/r/pi.R

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)