forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arrow-package.R
177 lines (159 loc) · 5.86 KB
/
arrow-package.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#' @importFrom stats quantile median na.omit na.exclude na.pass na.fail
#' @importFrom R6 R6Class
#' @importFrom purrr as_mapper map map2 map_chr map2_chr map_dbl map_dfr map_int map_lgl keep imap imap_chr
#' @importFrom purrr flatten reduce
#' @importFrom assertthat assert_that is.string
#' @importFrom rlang list2 %||% is_false abort dots_n warn enquo quo_is_null enquos is_integerish quos quo
#' @importFrom rlang eval_tidy new_data_mask syms env new_environment env_bind set_names exec
#' @importFrom rlang is_bare_character quo_get_expr quo_get_env quo_set_expr .data seq2 is_interactive
#' @importFrom rlang expr caller_env is_character quo_name is_quosure enexpr enexprs as_quosure
#' @importFrom rlang is_list call2 is_empty as_function as_label arg_match is_symbol is_call call_args
#' @importFrom rlang quo_set_env quo_get_env is_formula quo_is_call f_rhs parse_expr f_env new_quosure
#' @importFrom rlang new_quosures expr_text
#' @importFrom tidyselect vars_pull vars_rename vars_select eval_select
#' @importFrom glue glue
#' @useDynLib arrow, .registration = TRUE
#' @keywords internal
"_PACKAGE"
# TODO(ARROW-17666): Include notes about features not supported here.
supported_dplyr_methods <- list(
select = NULL,
filter = NULL,
collect = NULL,
summarise = NULL,
group_by = NULL,
groups = NULL,
group_vars = NULL,
group_by_drop_default = NULL,
ungroup = NULL,
mutate = NULL,
transmute = NULL,
arrange = NULL,
rename = NULL,
pull = NULL,
relocate = NULL,
compute = NULL,
collapse = NULL,
distinct = NULL,
left_join = NULL,
right_join = NULL,
inner_join = NULL,
full_join = NULL,
semi_join = NULL,
anti_join = NULL,
count = NULL,
tally = NULL,
rename_with = NULL,
union = NULL,
union_all = NULL,
glimpse = NULL,
show_query = NULL,
explain = NULL
)
#' @importFrom vctrs s3_register vec_size vec_cast vec_unique
.onLoad <- function(...) {
# Make sure C++ knows on which thread it is safe to call the R API
InitializeMainRThread()
for (cl in c("Dataset", "ArrowTabular", "RecordBatchReader", "arrow_dplyr_query")) {
for (m in names(supported_dplyr_methods)) {
s3_register(paste0("dplyr::", m), cl)
}
}
s3_register("dplyr::tbl_vars", "arrow_dplyr_query")
s3_register("pillar::type_sum", "DataType")
for (cl in c(
"Array", "RecordBatch", "ChunkedArray", "Table", "Schema",
"Field", "DataType", "RecordBatchReader"
)) {
s3_register("reticulate::py_to_r", paste0("pyarrow.lib.", cl))
s3_register("reticulate::r_to_py", cl)
}
# Create the .cache$functions list at package load time.
# We can't do this at package build time because list_compute_functions()
# needs the C++ library loaded
create_binding_cache()
if (tolower(Sys.info()[["sysname"]]) == "windows") {
# Disable multithreading on Windows
# See https://issues.apache.org/jira/browse/ARROW-8379
options(arrow.use_threads = FALSE)
# Try to set timezone database
configure_tzdb()
}
# Set interrupt handlers
SetEnableSignalStopSource(TRUE)
# Register extension types that we use internally
reregister_extension_type(vctrs_extension_type(vctrs::unspecified()))
invisible()
}
configure_tzdb <- function() {
# This is needed on Windows to support timezone-aware calculations
if (requireNamespace("tzdb", quietly = TRUE)) {
tzdb::tzdb_initialize()
set_timezone_database(tzdb::tzdb_path("text"))
} else {
msg <- paste(
"The tzdb package is not installed.",
"Timezones will not be available to Arrow compute functions."
)
packageStartupMessage(msg)
}
}
.onAttach <- function(libname, pkgname) {
# Just to be extra safe, let's wrap this in a try();
# we don't want a failed startup message to prevent the package from loading
try({
features <- arrow_info()$capabilities
# That has all of the #ifdef features, plus the compression libs and the
# string libraries (but not the memory allocators, they're added elsewhere)
#
# Let's print a message if some are off
if (some_features_are_off(features)) {
packageStartupMessage(
paste(
"Some features are not enabled in this build of Arrow.",
"Run `arrow_info()` for more information."
)
)
}
})
}
# Clean up the StopSource that was registered in .onLoad() so that if the
# package is reloaded we don't get an error from C++ informing us that
# a StopSource has already been set up.
.onUnload <- function(...) {
DeinitializeMainRThread()
}
# While .onUnload should be sufficient, devtools::load_all() does not call it
# (but it does call .onDetach()). It is safe to call DeinitializeMainRThread()
# more than once.
.onDetach <- function(...) {
DeinitializeMainRThread()
}
# True when the OS is linux + and the R version is development
# helpful for skipping on Valgrind, and the sanitizer checks (clang + gcc) on cran
on_linux_dev <- function() {
identical(tolower(Sys.info()[["sysname"]]), "linux") &&
grepl("devel", R.version.string)
}
option_use_threads <- function() {
!is_false(getOption("arrow.use_threads"))
}
option_compress_metadata <- function() {
!is_false(getOption("arrow.compress_metadata"))
}