Daisywang
Daisywang

Reputation: 307

Cannot document my R package 'NAMESPACE' issue

I am try to write my first R package and start a piece of test function. When I create a brand new package, I get a sample 'Hello.R' in R folder and 'Hello.Rd' in Man folder.

Then I delete the helloworld test function and type in my test code, wrote the documentation and try to create a new documentation:

#' A Cat Function
#'
#' This function allows you to express your love of cats.
#' @param love Do you love cats? Defaults to TRUE.
#' @keywords cats
#' @export
#' @examples
#' cat_function()

cat_function <- function(love=TRUE){
  if(love==TRUE){
    print("I love cats!")
  }
  else {
    print("I am not a cool person.")
  }
}

devtools::document()

Then I got this error:

> devtools::document()
Updating cat2 documentation
Loading cat2
First time using roxygen2. Upgrading automatically...
Updating roxygen version in /Users/daisywang/Desktop/R Package          Programming/cat2/DESCRIPTION
Warning: The existing 'NAMESPACE' file was not generated by roxygen2, and will     not be overwritten.
Warning messages:
1: In readLines(file) :
  incomplete final line found on '/Users/daisywang/Desktop/R Package     Programming/cat2/DESCRIPTION'
2: In readLines(file) :
  incomplete final line found on '/Users/daisywang/Desktop/R Package Programming/cat2/DESCRIPTION'

Then I tried to delete the "NAMESPACE" file in the folder, and got an infinite error:

Updating cat2 documentation
Loading cat2

 Show Traceback

 Rerun with Debug
 Error in dev_meta(pkg$package) (from hello.R#19) : 
  Namespace not found for cat2. Is it loaded? 

Any insight appreciated!!

Upvotes: 2

Views: 949

Answers (1)

fmic_
fmic_

Reputation: 2436

The line devtools::document() should not be part of your hello.R (or cat.R) file. This function is only meant to be called directly from the terminal.

Upvotes: 5

Related Questions