I am trying to stop R from displaying function code and environment information when I call a function. This function is part of an assignment for Coursera R Programming that was provided by the instructor. Here is the behavior:
R script:
makeVector <- function(x = numeric()) {
m <- NULL
set <- function(y) {
x <<- y
m <<- NULL
}
get <- function() x
setmean <- function(mean) m <<- mean
getmean <- function() m
list(set = set, get = get,
setmean = setmean,
getmean = getmean)
}
I run the following in the console:
> x <- 1:10
> makeVector(x)
And get:
$set
function (y)
{
x <<- y
m <<- NULL
}
<environment: 0x000000000967dd58>
$get
function ()
x
<environment: 0x000000000967dd58>
$setmean
function (mean)
m <<- mean
<environment: 0x000000000967dd58>
$getmean
function ()
m
<environment: 0x000000000967dd58>
It appears RStudio is returning function code and environment information rather than executing the function. Previously I ran debug(ls) and undebug(ls) as part of a quiz - it is my hunch that the debug() command has something to do with the behavior.
To fix the problem, I have already tried:
- deleting the RStudio-Desktop folder that contains RStudio settings. This reverted my appearance and global options to default, but the function calling behavior still happens.
- uninstalling and reinstalling both R and RStudio. The behavior still happens as above.
Does anyone know why RStudio is displaying function code and environment rather than executing the function?
I really appreciate the help! Thanks!