1

I seem to be having the same issue as is seen here so I started checking the environments that my frames/matrices are in. I have a character matrix, and a table that was imported as a list. I have been able to create a user-defined function that I have debugged and I can confirm that it runs through step by step assigning values in the character matrix to those needing change in the list.

{
    i = 1
    j = NROW(v)
    while (i < j) {
        if (v[i] %in% Convert[, 1]) {
            n <- match(v[i], Convert[, 1])
            v[i] <- Convert[n, 2]
        }
        i = i + 1
    }

}

That is the code in case you need to see what I am doing. The problem is whenever I check the environment of either of the list or the matrix, I get NULL (using environment()). I tried using assign() to create a new matrix. It seems, based on the link above, that this is an environment issue, but if the lists/matrices used have no environment, what is one to do?

Post Note: I have tried converting these to different formats (using as.character or as.list), but I don't know if this is even relevant if I can't get the environment issue resolved above.

DeCodened
  • 59
  • 2
  • 8

1 Answers1

0

environment() works only for functions and not for variables. In fact the environment function gives the enclosing environment that makes sense only for function and not the binding environment you are interested in case of a variable. If you want the binding environment use pryr package

library(pryr)
where("V")

Here an example

    e<-new.env()
     e$test<-function(x){x}
environment(e$test)

yu can see the environment here is the global environment because you defined the function there, but obviously the binding environment(that is the environment where you find the name of the variabile) is e.

http://adv-r.had.co.nz/Environments.html

Here to understand better the problem

Federico Manigrasso
  • 1,130
  • 1
  • 7
  • 11
  • Thank you! So,as I understand this, if I were to follow the guidance in the link above using the assign() function, that would ENSURE that any new assignments were going to the right place? I would enter something like: assign('v',v,envir=.GlobalEnv) and then my changes should be seen in that new matrix? Also, I tried calling library(pryr) and received a message indicating there is no package named 'pryr'. I assume if I got that library, I could call "where()" and find out where these current tables are stored? Thanks for your help! – DeCodened May 24 '17 at 19:26
  • install.packages("pryr") you have to install the package before :)..exactly with assign you can specify the environment of the bounding variabile. – Federico Manigrasso May 25 '17 at 06:58