Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARROW-12841: [R] Add examples to more function documentation - part 2 #10368

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion r/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Imports:
utils,
vctrs
Roxygen: list(markdown = TRUE, r6 = FALSE, load = "source")
RoxygenNote: 7.1.1
RoxygenNote: 7.1.1.9001
VignetteBuilder: knitr
Suggests:
decor,
Expand Down
2 changes: 2 additions & 0 deletions r/R/compression.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Codec$create <- function(type = "gzip", compression_level = NA) {
#' "zstd", "lz4", "lzo", or "bz2", case insensitive.
#' @return Logical: is `type` available?
#' @export
#' @examples
#' codec_is_available("gzip")
codec_is_available <- function(type) {
util___Codec__IsAvailable(compression_from_name(type))
}
Expand Down
12 changes: 12 additions & 0 deletions r/R/dataset-format.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@
#' It returns the appropriate subclass of `FileFormat` (e.g. `ParquetFileFormat`)
#' @rdname FileFormat
#' @name FileFormat
#' @examplesIf arrow_with_dataset()
#' ## Semi-colon delimited files
#' # Set up directory for examples
#' tf <- tempfile()
#' dir.create(tf)
#' on.exit(unlink(tf))
#' write.table(mtcars, file.path(tf, "file1.txt"), sep = ";", row.names = FALSE)
#'
#' # Create FileFormat object
#' format <- FileFormat$create(format = "text", delimiter = ";")
#'
#' open_dataset(tf, format = format)
#' @export
FileFormat <- R6Class("FileFormat", inherit = ArrowObject,
active = list(
Expand Down
24 changes: 24 additions & 0 deletions r/R/dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,30 @@
#' @export
#' @seealso `vignette("dataset", package = "arrow")`
#' @include arrow-package.R
#' @examplesIf arrow_with_dataset()
#' # Set up directory for examples
#' tf <- tempfile()
#' dir.create(tf)
#' on.exit(unlink(tf))
#' \dontrun{
#' write_parquet(mtcars[1:10,], file.path(tf, "file1.parquet"))
#' write_parquet(mtcars[11:20,], file.path(tf, "file2.parquet"))
#' write_parquet(mtcars[21:32,], file.path(tf, "file3.parquet"))
#'
#' # You can specify a directory containing the files for your dataset and
#' # open_dataset will scan all files in your directory.
#' open_dataset(tf)
#'
#' # You can also supply a vector of paths
#' open_dataset(c(file.path(tf, "file3.parquet"), file.path(tf, "file2.parquet")))
#' }
#' ## You must specify the file format if using a format other than parquet.
#' write_csv_arrow(mtcars[1:10,], file.path(tf, "file1.csv"))
#' write_csv_arrow(mtcars[11:20,], file.path(tf, "file2.csv"))
#' # This line will results in errors when you try to work with the data
#' \dontrun{open_dataset(c(file.path(tf, "file1.csv"), file.path(tf, "file2.csv")))}
#' # This is the correct way to open a dataset containing CSVs
#' open_dataset(c(file.path(tf, "file1.csv"), file.path(tf, "file2.csv")), format = "csv")
open_dataset <- function(sources,
schema = NULL,
partitioning = hive_partition(),
Expand Down
2 changes: 2 additions & 0 deletions r/R/flight.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#' @param path file system path where the Python module is found. Default is
#' to look in the `inst/` directory for included modules.
#' @export
#' @examples
#' \dontrun{load_flight_server("demo_flight_server")}
load_flight_server <- function(name, path = system.file(package = "arrow")) {
reticulate::import_from_path(name, path)
}
Expand Down
4 changes: 4 additions & 0 deletions r/R/ipc_stream.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
#' serialize data to a buffer.
#' [RecordBatchWriter] for a lower-level interface.
#' @export
#' @examples
#' tf <- tempfile()
#' on.exit(unlink(tf))
#' write_ipc_stream(mtcars, tf)
write_ipc_stream <- function(x, sink, ...) {
x_out <- x # So we can return the data we got
if (is.data.frame(x)) {
Expand Down
24 changes: 24 additions & 0 deletions r/R/scalar.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,33 @@
#' @docType class
#'
#' @description A `Scalar` holds a single value of an Arrow type.
#'
#' @section Methods:
#' `$ToString()`: convert to a string
#' `$as_vector()`: convert to an R vector
#' `$as_array()`: convert to an Arrow `Array`
#' `$Equals(other)`: is this Scalar equal to `other`
#' `$ApproxEquals(other)`: is this Scalar approximately equal to `other`
#' `$is_valid`: is this Scalar valid
#' `$null_count`: number of invalid values - 1 or 0
#' `$type`: Scalar type
#'
#' @name Scalar
#' @rdname Scalar
#' @examples
#' Scalar$create(pi)
#' Scalar$create(404)
#' # If you pass a vector into Scalar$create, you get a list containing your items
#' Scalar$create(c(1, 2, 3))
#'
#' # Comparisons
#' my_scalar <- Scalar$create(99)
#' my_scalar$ApproxEquals(Scalar$create(99.00001)) # FALSE
#' my_scalar$ApproxEquals(Scalar$create(99.000009)) # TRUE
#' my_scalar$Equals(Scalar$create(99.000009)) # FALSE
#' my_scalar$Equals(Scalar$create(99L)) # FALSE (types don't match)
#'
#' my_scalar$ToString()
#' @export
Scalar <- R6Class("Scalar",
inherit = ArrowDatum,
Expand Down
15 changes: 15 additions & 0 deletions r/man/FileFormat.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions r/man/Scalar.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions r/man/codec_is_available.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions r/man/load_flight_server.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions r/man/open_dataset.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions r/man/write_ipc_stream.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.