Github user HyukjinKwon commented on a diff in the pull request:
https://github.com/apache/spark/pull/15239#discussion_r82367394
--- Diff: R/pkg/R/SQLContext.R ---
@@ -341,11 +342,13 @@ setMethod("toDF", signature(x = "RDD"),
#' @name read.json
#' @method read.json default
#' @note read.json since 1.6.0
-read.json.default <- function(path) {
+read.json.default <- function(path, ...) {
sparkSession <- getSparkSession()
+ options <- varargsToStrEnv(...)
# Allow the user to have a more flexible definiton of the text file path
paths <- as.list(suppressWarnings(normalizePath(path)))
read <- callJMethod(sparkSession, "read")
+ read <- callJMethod(read, "options", options)
--- End diff --
Oh, I see.
In R, it seems we can't duplicatedly set paths.
In Scala and Python, for reading it takes all paths set in option and as
arguments for reading. For writing, the argument overwrites the path set in
option.
For R, in more details, It seems we can't simply specify the same keyword
argument both.
- `read.json()`
**Duplicated keywords**
```r
> read.json(path = "hyukjin.json", path = "felix.json")
Error in dispatchFunc("read.json(path)", x, ...) :
argument "x" is missing, with no default
```
**With a single keyword argument**
```
> collect(read.json("hyukjin.json", path = "felix.json"))
NAME
1 Felix
```
- `read.df()`
**Duplicated keywords**
```r
> read.df(path = "hyukjin.json", path = "felix.json", source = "json")
Error in f(x, ...) :
formal argument "path" matched by multiple actual arguments
```
**With a single keyword argument**
```r
> read.df("hyukjin.json", path = "felix.json", source = "json")
Error: length(x) > 0 is not TRUE
```
This case, it seems "hyukjin.json" became the third argument, `schema`.
In the case of **With a single keyword argument**, it seems `path` becomes
`felix.json`. For example, as below:
```r
> tmp <- function(path, ...) {
+ print(path)
+ }
>
> tmp("a", path = "b")
[1] "b"
```
For `...` arguments, it seems it throws an exception when we use some
variables mix-and-matched as below:
```r
> varargsToStrEnv("a", path="b")
Error in env[[name]] <- value :
attempt to use zero-length variable name"
```
However, it seems fine if they are all non-keywords arguments or keywords
arguments as below:
```r
> varargsToStrEnv("a", 1, 2, 3)
> varargsToStrEnv(a="a", b=1, c=2, d=3)
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]