Watts-College / cpp-527-fall-2021

A course shell for CPP 527 Foundations of Data Science II
https://watts-college.github.io/cpp-527-fall-2021/
2 stars 6 forks source link

errors building r package #6

Open lecy opened 3 years ago

lecy commented 3 years ago

I’m working on the package assignment , I did all the steps however when I use to test the create_game() function I got this error:

 Error in create_game() : could not find function "create_game"

Also when I used :

setwd( "montyhall" )

I got this:

Error in setwd("montyhall") : cannot change working directory

Then when I use

devtools::document()

I got only this two line :

i Updating montyhall document
i Loading montyhall

instead of this:

# Updating montyhall documentation
# Updating roxygen version in C:\Users\jdlecy\Documents\montyhall/DESCRIPTION
# Writing NAMESPACE
# Loading montyhall
# Writing create_game.Rd

What is wrong?

lecy commented 3 years ago

It might be an issue related to whether you are in the proper folder when running each step.

image

For the first step you will create the montyhall folder in whatever directory you are working in (I'm using documents here):

getwd()
usethis::create_package( "montyhall" )

documents  # should be here first 
├─ montyhall
│  ├─ R

You run the document() function from inside the new montyhall folder after you have moved your documented code into the R folder:

setwd( "montyhall" )
getwd()
devtools::document()

documents  
├─ montyhall    # should be here now
│  ├─ R              # place your R scripts in here  

If your document() task was successful you will find new *.Rd (R documentation) files in the new man (manual) folder. One file for each function (change_door.Rd, create_game.Rd, etc.). These are the help files for each function.

Then return to the default directory before trying to install the package.

setwd( ".." )
getwd()   # back to documents 
devtools::install( "montyhall" )

documents    # should be back here 
├─ montyhall  
│  ├─ R
│  ├─ man   # new *.rd files were added here  
Rami-Assaad commented 3 years ago

Dear Prof. Jesse,

I’ve completed all the steps of GitHub Hosting tell reaching Push Origin using the desktop app without facing any issue, however after I use devtools::install_github( "..." ) I got this error when testing it in a new R console:

Downloading GitHub repo
Error: Failed to install 'montyhall' from GitHub:
Line starting 'behind it and two ha ...' is malformed!

Why I'm encountering this issue?

lecy commented 3 years ago

Unlike R, roxygen comments are like YAML headers - they parse data using spaces so can be a little sensitive.

I searched your script for the text in the error and found:

#' @details
#'   The game setup replicates the game on the TV show "Let's
#'   Make a Deal" where there are three doors for a contestant
#'   to choose from, one of which has a car behind it and two 
#'   have goats. The contestant selects a door, then the host

Note that only that line has a space after it:

#'   Make a Deal" where there are three doors for a contestant
#'   to choose from, one of which has a car behind it and two[SPACE]
#'   have goats. The contestant selects a door, then the host

Try removing that and see if it works.

"malformed line" often means extra or missing spaces, carriage returns, special characters.