4

I am trying to install the r package sowas and unfortunately it is too old to implement in the new versions of r.

According to the author you can use the package using the source() function to gain access to the code but I have not been able to figure out how to do that.

Any help is appreciated.

Here is a link to the package I described as it is not a CRAN package: http://tocsy.pik-potsdam.de/wavelets/

4
  • 1
    Just unpack the tar or zip archive and look at its content. You will find some interesting files in subfolder R. Commented Oct 27, 2012 at 16:56
  • 1
    I think the zip file is a Windows build. If you download the linux version from here and extract it, you will be able to see the code in the R directory. Commented Oct 27, 2012 at 17:24
  • even if you load the R code, you'll need some way to register (or even compile) the C codes in the src file. How you do this will depend on which OS etc. you are running. Commented Oct 27, 2012 at 21:42
  • I did look in the unzipped package but most of the files were unreadable. As was mentioned i believe the code needs to be compiled into R code. Does anyone know how to do that? I am running R in windows 7 Commented Oct 28, 2012 at 3:34

2 Answers 2

4

The .zip file is a windows binary and as such it won't be too interesting. What you'll want to look at is the contents of the .tar.gz archive. You can extract those contents and then look at the code in the R subdirectory.

You could also update the package to work with new versions of R so that you can actually build and install the package. To do so you could unpack the .tar.gz as before but now you'll need to add a NAMESPACE file. This is just a plaintext file at the top of the package directory that has a form like:

export(createar)
export(createwgn)
export(criticalvaluesWCO)
export(criticalvaluesWSP)
export(cwt.ts)
export(plot.wt)
export(plotwt)
export(readmatrix)
export(readts)
export(rk)
export(wco)
export(wcs)
export(writematrix)
export(wsp)

Where you have an export statement for any function in the package that you actually want to be able to use. If a function isn't exported then the functions in the package still have access to that function but the user can't use it (as easily). Once you do that you should be able to build and install the package.

I took the liberty of doing some of this already. I haven't actually taken the time to figure out which functions are useful and should be exported and just assumed that if a help page was written for the function that it should be exported and if there wasn't a help page then I didn't export it. I used Rd2roxygen to convert the help pages to roxygen code (because that's how I roll) and had to do a little bit of cleanup after that but it seems to install just fine.

So if you have the devtools package installed you should actually be able to install the version I modified directly by using the following commands

library(devtools)
install_github("SOWAS", "Dasonk")

Personally I would recommend that you go the route of adding the NAMESPACE file and what not directly as then you'll have more control over the code and be more able to fix any problems that might occur when using the package. Or if you use git you could fork my repo and continue fixing things from there. Good luck.

Sign up to request clarification or add additional context in comments.

Comments

2

If you want to see the source code of a particular function, then just type the name of the function without the braces and press enter. You will see the code.

For example type var in command prompt to see it's code.

> var
function (x, y = NULL, na.rm = FALSE, use) 
{
    if (missing(use)) 
        use <- if (na.rm) 
            "na.or.complete"
        else "everything"
    na.method <- pmatch(use, c("all.obs", "complete.obs", "pairwise.complete.obs", 
        "everything", "na.or.complete"))
    if (is.na(na.method)) 
        stop("invalid 'use' argument")
    if (is.data.frame(x)) 
        x <- as.matrix(x)
    else stopifnot(is.atomic(x))
    if (is.data.frame(y)) 
        y <- as.matrix(y)
    else stopifnot(is.atomic(y))
    .Call(C_cov, x, y, na.method, FALSE)
}
<bytecode: 0x0000000008c97980>
<environment: namespace:stats>

1 Comment

just typing the function in the console does not always work. typing 'deviance' from the stats package into the console does not yield the source function.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.