How to configure RStudio package build to work across multiple machines
Asked Answered
P

4

9

This question has been asked by another user on the RStudio help page here but has gone unanswered.

Basically, I've gone through all the steps:

(1) Installed Xcode

(2) Downloaded and installed command line tools

(3) Installed MacTex

(4) Selected the directory containing the R package with accompanying description file.

This package compiled just fine on the Mac I first used to build it. Now, however, I am being told that RStudio cannot detect the DESCRIPTION file, even though it is sitting right there in the build directory. I've attached a screenshot.

The error message I get is:

ERROR: The build directory does not contain a DESCRIPTION file so cannot be built as a package.

Anyone know what I'm missing? I've attached a screenshot for reference. Full disclosure: this is work for a commercial application.

Arrows point out that the DESCRIPTION file exists in the build directory

Perryperryman answered 1/2, 2014 at 2:40 Comment(3)
I've been working on a package too recently. Most frustratingly cool thing I've done with R and R studio. First question: did you set your working directory? Second question / comment: your error is probably not related to latex, but have you confirmed that other latex interfaces like LaTeXit or Texshop work properly? Last question, did you install and require roxygen2? Also, to avoid having this flagged as too localised, you might want to change it to "how does everyone configure their package build so as to be able to work on multiple machines?". Just a thought...Amari
Hey Andy, great comments. I went through all those checks. Everything you suggested checks out, with the exception that I'm not sure what you mean by "requiring" roxygen2--seems to me that RStudio would do this implicitly, but maybe I need to make it explicit somewhere? Also, changed the title. Good tip.Perryperryman
Quick note to anyone else who might have experienced something like this: you can build your packages straight from the UNIX command line using R CMD build packagedirectory. The manual solution gets me what I need. Would still be really nice to figure out what's going on with RStudio though.Perryperryman
A
4

Following is an outline of how I've approached this for a package that we'll call mypack.

Update R and Rstudio

This should be the first thing you do. Update everything...

Create the package skeleton

Use the roxygen2 package to create the mypack package skeleton. From your IDE, try this:

library(roxygen2)
package.skeleton('mypack')

See http://cran.r-project.org/web/packages/roxygen2/roxygen2.pdf for more details.

Edit the description file

Edit the DESCRIPTION file using a reader that lets me see non-printing characters. It's worth checking to see if there are any odd characters hiding in your file. RStudio is a good editor to use.

Compare your DESCRIPTION file contents with someone else's github repositories, for example the plyr description file.

Also, there's a related question here with an answer that explains some more of how the DESCRIPTION file is used.

Building the package

I use a script (below) to build my package from within Rstudio, rather than using Rstudio's canned options. I don't like having to remember to switch between the usual IDE and some project.

You'll need to have [devtools][3] installed to make this work.

setwd('~/Documents/projects/Rcode')
# remove the old version
try(detach(name = "package:mypack",unload = TRUE))
# load the packages we need for building / documentation
library("roxygen2")  # could use "require"
# generate documentation
roxygenize(package.dir = "mypack")

# now we actually build and install the package
system("R CMD build mypack")
system("R CMD INSTALL --preclean mypack_1.00.tar.gz")
system("R CMD check mypack")
# check for old documentation
try(file.remove(file.path(getwd(),"mypack.pdf")))
# generate new documentation
system("R CMD Rd2pdf mypack")
# and finally, make it available.
library("mypack")

Disclaimer: I am fully aware that I may have some of the above in the wrong order, or be doing something daft. I'm just not sure what, and it works at the moment.

Creating package documentation

I have R-markdown in the headers of all of my functions, so the help files are created as ./man/*.Rd (where * is the function name) automagically when I execute this script. Again, have a look at the plyr github to get a feel for this.

I also wrote a vignette for this package. That's an .Rnw file, which can be edited in Rstudio or any other text editor. The .Rnw file is basically latex with embedded knitr chunks. Rstudio's editor has an option to compile this independently of the package itself. This seems to be a great solution, and the above script recompiles the vignettes whenever I update my code, which is a good check on everything.

Cross-platform installation

I know this script works on multiple macs, but have never had the misfortune to have to use a windows machine to compile. A colleague of mine is using the compiled package on windows without any trouble, though.

Resources

Useful resources for this include:

Amari answered 1/2, 2014 at 16:33 Comment(0)
D
9

I came across an error like this just now (except I had previously been able to build the package without incident).

Turns out my error was caused by a poorly formed DESCRIPTION file. Fixing the syntax there allowed my package to build.

Detest answered 20/7, 2015 at 12:36 Comment(2)
Having just experienced the same problem, I learned the hard way that "DESCRIPTION uses a simple file format... When values span multiple lines, they need to be indented" (from R Packages by Hadley Wickham)Specification
You can check if this might be the problem with devtools::build() it gives an a little more informative error message, e.g.: "Error: Line starting 'foo bar foo bar foo ...' is malformed!"Voidance
A
4

Following is an outline of how I've approached this for a package that we'll call mypack.

Update R and Rstudio

This should be the first thing you do. Update everything...

Create the package skeleton

Use the roxygen2 package to create the mypack package skeleton. From your IDE, try this:

library(roxygen2)
package.skeleton('mypack')

See http://cran.r-project.org/web/packages/roxygen2/roxygen2.pdf for more details.

Edit the description file

Edit the DESCRIPTION file using a reader that lets me see non-printing characters. It's worth checking to see if there are any odd characters hiding in your file. RStudio is a good editor to use.

Compare your DESCRIPTION file contents with someone else's github repositories, for example the plyr description file.

Also, there's a related question here with an answer that explains some more of how the DESCRIPTION file is used.

Building the package

I use a script (below) to build my package from within Rstudio, rather than using Rstudio's canned options. I don't like having to remember to switch between the usual IDE and some project.

You'll need to have [devtools][3] installed to make this work.

setwd('~/Documents/projects/Rcode')
# remove the old version
try(detach(name = "package:mypack",unload = TRUE))
# load the packages we need for building / documentation
library("roxygen2")  # could use "require"
# generate documentation
roxygenize(package.dir = "mypack")

# now we actually build and install the package
system("R CMD build mypack")
system("R CMD INSTALL --preclean mypack_1.00.tar.gz")
system("R CMD check mypack")
# check for old documentation
try(file.remove(file.path(getwd(),"mypack.pdf")))
# generate new documentation
system("R CMD Rd2pdf mypack")
# and finally, make it available.
library("mypack")

Disclaimer: I am fully aware that I may have some of the above in the wrong order, or be doing something daft. I'm just not sure what, and it works at the moment.

Creating package documentation

I have R-markdown in the headers of all of my functions, so the help files are created as ./man/*.Rd (where * is the function name) automagically when I execute this script. Again, have a look at the plyr github to get a feel for this.

I also wrote a vignette for this package. That's an .Rnw file, which can be edited in Rstudio or any other text editor. The .Rnw file is basically latex with embedded knitr chunks. Rstudio's editor has an option to compile this independently of the package itself. This seems to be a great solution, and the above script recompiles the vignettes whenever I update my code, which is a good check on everything.

Cross-platform installation

I know this script works on multiple macs, but have never had the misfortune to have to use a windows machine to compile. A colleague of mine is using the compiled package on windows without any trouble, though.

Resources

Useful resources for this include:

Amari answered 1/2, 2014 at 16:33 Comment(0)
C
3

I recently had exactly the same problem - my package would not compile under RStudio with an error saying that the package directory does not contain the DESCRIPTION file. I solved the problem by changing encoding of the DESCRIPTION file to ANSI.

Chancre answered 23/3, 2015 at 22:38 Comment(1)
You can check for non-ASCII characters via using: tools::showNonASCIIfile("DESCRIPTION")Voidance
S
-3

Change:

Description: Line1

         Line2 

         Line3.

To:

Description: Line1 Line2 Line3.

It will work!

Salinger answered 26/9, 2016 at 15:11 Comment(1)
Why would this work? Having line breaks in your description should not be a problem. See here for a text book explanation and e.g. here for a real life example.Demagogy

© 2022 - 2024 — McMap. All rights reserved.