From 3578a3f858136a8abcd2f708f38a8dff6225ec42 Mon Sep 17 00:00:00 2001 From: maechler Date: Fri, 7 Feb 2025 20:16:21 +0000 Subject: [PATCH] as.environment() argument name is `x` git-svn-id: https://svn.r-project.org/R/trunk@87707 00db46b3-68df-0310-9c12-caf00c1e9a41 --- doc/NEWS.Rd | 4 ++++ src/main/envir.c | 5 +++-- tests/reg-tests-1e.R | 6 ++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/doc/NEWS.Rd b/doc/NEWS.Rd index b2405144dc..ee74022ffa 100644 --- a/doc/NEWS.Rd +++ b/doc/NEWS.Rd @@ -550,6 +550,10 @@ \item \command{R CMD Rd2pdf} can now render the package manual from a \option{--latex} installation also when the help contains figures. + + \item The argument of \code{as.environment()} is named \code{x} now, + not \code{object}, as it was always documented and shown when + printing it; thanks to \I{Gael Millot}'s \PR{18849}. } } } diff --git a/src/main/envir.c b/src/main/envir.c index fc6e26dd67..259dd2003c 100644 --- a/src/main/envir.c +++ b/src/main/envir.c @@ -1,6 +1,6 @@ /* * R : A Computer Language for Statistical Data Analysis - * Copyright (C) 1999--2024 The R Core Team. + * Copyright (C) 1999--2025 The R Core Team. * Copyright (C) 1995, 1996 Robert Gentleman and Ross Ihaka * * This program is free software; you can redistribute it and/or modify @@ -3302,7 +3302,7 @@ do_as_environment(SEXP call, SEXP op, SEXP args, SEXP rho) { SEXP arg = CAR(args), ans; checkArity(op, args); - check1arg(args, call, "object"); + check1arg(args, call, "x"); if(isEnvironment(arg)) return arg; /* DispatchOrEval internal generic: as.environment */ @@ -3866,6 +3866,7 @@ attribute_hidden SEXP do_getRegNS(SEXP call, SEXP op, SEXP args, SEXP rho) return R_NilValue; // -Wall } +// .Internal(getNamespaceRegistry()) attribute_hidden SEXP do_getNSRegistry(SEXP call, SEXP op, SEXP args, SEXP rho) { checkArity(op, args); diff --git a/tests/reg-tests-1e.R b/tests/reg-tests-1e.R index cc9d47fd35..d9f66d6adb 100644 --- a/tests/reg-tests-1e.R +++ b/tests/reg-tests-1e.R @@ -1833,6 +1833,12 @@ options(op)# reverting ## in R < 4.4.z only *one* message .. "NA/Inf replaced by ...." +## as.environment(x = .) should work +ee <- as.environment(x = list(a = 1, bb = 2)) +stopifnot(is.environment(ee), length(ee) == 2L) +## instead, for R <= 4.4.z, no name or as.environment(object = .) was needed + + ## keep at end rbind(last = proc.time() - .pt,