0

I'm trying to turn this function found here into an R package. I'm following the directions found here.

Here are the steps I take:

1) Load required library

library(devtools)

2) Go to a new location

setwd('C:\\myRpkgs\\')

3) Create skeleton

create('conveniencePkg')

4) Copy function to file and save in 'C:\\myRpkgs\\conveniencePkg\\R\\lsos.R'

5) Run document function

setwd("./conveniencePkg")
document()

6) Install package

setwd("..")
install("conveniencePkg")

7) Load library

library(conveniencePkg)

8) try to use lsos function

>lsos()
Error in is.na(obj.dim)[, 1] : subscript out of bounds

Result is the following error:

> traceback()
2: .ls.objects(..., order.by = "Size", decreasing = TRUE, head = TRUE, 
       n = n)
1: conveniencePkg::lsos()

The function runs fine if I put it into an R file and just use the source() function. Anything seem incorrect in the above steps?

Community
  • 1
  • 1
screechOwl
  • 27,310
  • 61
  • 158
  • 267
  • 1
    The error message is pretty simple. Why don't you just `debug()` the function `.ls.objects` (which I presume is from [here](http://stackoverflow.com/q/1358003/324364)) and see exactly why `obj.dim` doesn't have the right dimensions? Then you'd actually know what went wrong, which seems like the first step to solving it. – joran Sep 29 '14 at 14:46
  • 1
    it doesn't work because there are no objects in the workspace when you load the package into a clean r session. it works when you source it because you are also creating the lsos object so obj.dim has the correct dimensions to return [, 1] without error – rawr Sep 29 '14 at 15:22
  • @rawr : You're right. Didn't realize package objects are treated differently than source() generated objects. Thanks for pointing that out. – screechOwl Sep 29 '14 at 15:59

0 Answers0