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 6860081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:21:49+00:00 2026-05-27T02:21:49+00:00

Having just spent an hour chasing a ‘matrix vs data.frame’ bug in my code,

  • 0

Having just spent an hour chasing a ‘matrix vs data.frame’ bug in my code, I would very much like to understand the following:

tmp <-
  structure(c(4L, 7L, 5L, 12L, 6L, 11L, 9L, 3L, 1L, 2L, 10L, 8L),
            .Dim = c(6L, 2L), .Dimnames = list(NULL, c("col1", "col2")))

## 1. This works:
plot(col2 ~ col1, data = tmp)

## 2. This doesn't work:
plot(col2 ~ col1, data = tmp, main = "hello")
## -> Error in FUN(X[[1L]], ...) : numeric 'envir' arg not of length one

## 3. This works:
plot(col2 ~ col1, data = as.data.frame(tmp), main = "hello")

It seems to me that either 1 and 2 should both work, or both fail. The fact that 1 worked while 2 failed lead me very far astray in trying to get my code working.

My question is: why can you sometimes use a formula to plot matrix columns, instead of always or never? What happens when I add a title to my plot to cause it to fail?

Edit:
I suspected I must have broken something myself, so I have already tried this exact code in multiple fresh R instances. My sessionInfo is:

> sessionInfo()
R version 2.12.1 (2010-12-16)
Platform: i686-pc-linux-gnu (32-bit)

locale:
 [1] LC_CTYPE=en_CA.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_CA.UTF-8        LC_COLLATE=en_CA.UTF-8    
 [5] LC_MONETARY=C              LC_MESSAGES=en_CA.UTF-8   
 [7] LC_PAPER=en_CA.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
> 

Edit:

Here’s the traceback() following the failed plot command:

> > traceback()
4: FUN(X[[1L]], ...)
3: lapply(dots, eval, data, parent.frame())
2: plot.formula(col2 ~ col1, data = tmp, main = "hello")
1: plot(col2 ~ col1, data = tmp, main = "hello")
> 

Edit:

Upgrading to 2.14 has resolved the issue.

  • 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-05-27T02:21:50+00:00Added an answer on May 27, 2026 at 2:21 am

    Based on the comments thread following the question, it’s clear that this was a problem in R-2.12.1, and isn’t for R-2.14.0.

    The R-2.13.0 section of the NEWS file is presumably referring to this bug fix when it mentions that

    * plot(<formula>, data=<matrix>,..) now works in more cases;
      similarly for points(), lines() and text().
    

    (NOTE: this answer is based on the digging of Tyler and numerous posters above. I’m elevating the conclusions of that thread to answer status, as a possibly useful reminder of the kind of bug-fixes that are included in each version of R.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having just spent over an hour debugging a bug in our code which in
I just spent almost an hour trying to figure out an issue with having
I'm having a problem reading and processing data from my server. I've spent hours
Having just spent a frustrating amount of time configuring an automated build with psake
Having just spent ages debugging this, I'm keen to understand what exactly is going
Having just read the first four chapters of Refactoring: Improving the Design of Existing
Having just pulled my hair off because of a difference, I'd like to know
Having just updated Mono to 2.6.3 (on OS X), I noticed in the installer
Having just started with MVC 2 I notice that in their starter template they
... after having just read http://www.cocoadev.com/index.pl?CocoaInsecurity ... I am curious to know about your

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.