Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8117435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:10:11+00:00 2026-06-06T04:10:11+00:00

I ran across an oddity here: https://stackoverflow.com/a/11084038/636656 It appears that assigning to a name

  • 0

I ran across an oddity here:

https://stackoverflow.com/a/11084038/636656

It appears that assigning to a name that is the same as a base function still allows you to use the base function:

> print <- FALSE
> print
[1] FALSE
> print("hi")
[1] "hi"
> 
> sum <- FALSE
> sum(1:10)
[1] 55
> sum
[1] FALSE

By contrast, assigning a function to the same name as a base function does not produce the same behavior:

> sum <- function(x) x^2
> sum(1:10)
 [1]   1   4   9  16  25  36  49  64  81 100
> sum
function(x) x^2

I’m aware that these sit in different namespaces, but I’m curious about two things:

  1. Why: Is this a failsafe to avoid difficult-to-recover-from behavior (e.g. if you overwrite rm)? What is the principle that predicts this behavior?

  2. How: Are there different lookup routines for functions and logicals by namespace?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T04:10:12+00:00Added an answer on June 6, 2026 at 4:10 am

    When evaluating a call to print(), R searches (along its ordinary search path) for a function with the name print. Your object print <- TRUE has the right name, but isn’t a function, so the search shoots right past to the the first function having the right name.

    Here’s John Chambers’ explanation, from “Chapter 13: How R works” in Software for Data Analysis: Programming with R.

    The evaluation of the function call begins by looking for a function corresponding to the name. The rules for “looking for” are the same as the general rules for evaluating names mentioned above, except that the evaluator silently ignores any object found that is not a function, allowing local non-function objects with the same name as non-local functions, a concession motivated by people’s tendency to assign objects names such as “c”.

    (I especially like that last bit about this being “a concession motivated by people’s tendency to …” 😉


    Since you’re interested in this, it’s also worth having a look at match.fun(), which is designed to “extract the desired function object while avoiding undesired matching to objects of other types”. It includes the following line, which nicely illustrates the strategy used by both and the evaluator:

    FUN <- get(as.character(FUN), mode = "function", envir = envir)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I just ran across this oddity. It appears that Ubuntu has a feature
I ran across a compilation issue today that baffled me. Consider these two container
I ran across an interesting issue today. We have an application that utilizes Zend
I ran across a comment that made me wonder: If you use a sharding
I ran across a tutorial that had the following syntax: rails generate model User
I ran across some very interesting code that makes me wonder about what bool
I ran across an assertion that HashSet<T>.Contains() is an O(1) operation. This surprised me
I ran across some code like this today; having a flow control flag that
I downloaded Chromium 's code base and ran across the WTF namespace . namespace
I'm trying to fix a design flaw that I recently ran across in some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.