From fdecb6a0bee5fb482705de14c161853fe2ea2b41 Mon Sep 17 00:00:00 2001 From: Jonathan Keane Date: Fri, 6 Oct 2023 09:21:31 -0500 Subject: [PATCH] GH-38049: [R] Prevent `on_rosetta()` from warning (#38052) ### Rationale for this change Stop extraneous warnings. ### What changes are included in this PR? Prevent warning when detecting translation, but on x86 ### Are these changes tested? Yes ### Are there any user-facing changes? Yes, there will be fewer extraneous warnings. * Closes: #38049 Authored-by: Jonathan Keane Signed-off-by: Dewey Dunnington --- r/R/arrow-package.R | 5 +++-- r/tests/testthat/test-arrow-pacakge.R | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 r/tests/testthat/test-arrow-pacakge.R diff --git a/r/R/arrow-package.R b/r/R/arrow-package.R index 09183250ba3e0..54218bbf85476 100644 --- a/r/R/arrow-package.R +++ b/r/R/arrow-package.R @@ -183,7 +183,7 @@ configure_tzdb <- function() { # 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({ - # On MacOS only, Check if we are running in under emulation, and warn this will not work + # On MacOS only, Check if we are running in under emulation, and warn this will not work if (on_rosetta()) { packageStartupMessage( paste( @@ -242,8 +242,9 @@ on_macos_10_13_or_lower <- function() { } on_rosetta <- function() { + # make sure to suppress warnings and ignore the stdout + stderr so that this is silent identical(tolower(Sys.info()[["sysname"]]), "darwin") && - identical(system("sysctl -n sysctl.proc_translated", intern = TRUE), "1") + identical(suppressWarnings(system("sysctl -n sysctl.proc_translated", intern = TRUE, ignore.stderr = TRUE, ignore.stdout = TRUE)), "1") } option_use_threads <- function() { diff --git a/r/tests/testthat/test-arrow-pacakge.R b/r/tests/testthat/test-arrow-pacakge.R new file mode 100644 index 0000000000000..2d79467fa30a9 --- /dev/null +++ b/r/tests/testthat/test-arrow-pacakge.R @@ -0,0 +1,21 @@ +# 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. + +test_that("on_rosetta() does not warn", { + # There is no warning + expect_warning(on_rosetta(), NA) +})