DS4PS / cpp-527-fall-2020

http://ds4ps.org/cpp-527-fall-2020/
0 stars 1 forks source link

Build Package Error #21

Open ecking opened 3 years ago

ecking commented 3 years ago

Hi Professor,

I'm working building the monty hall package and I'm going to test the package in a new r file and it's throwing an error: Error in sample(x = rep(c("goat", "car"), c(num.goats, num.cars)), size = (num.goats + : argument "num.goats" is missing, with no default

I'm not sure why I'm receiving this error if my lab files run just fine. Any idea on what I should do?

lecy commented 3 years ago

How are you testing the package? I would need to know what you are trying to run to know what the error might be.

malmufre commented 3 years ago

Hello @lecy I have done the steps and I reached to this point and received the following errors. When I ran this code I got this

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

The working directory was changed to C:/Users/athma/Downloads/CPP527/Week 3/montyhall inside a notebook chunk. The working directory will be reset when the chunk is finished running. Use the knitr root.dir option in the setup chunk to change the working directory for notebook chunks.Updating montyhall documentation Loading montyhall [C:\Users\athma\Downloads\CPP527\Week 3\montyhall\R\monty-hall-problem.R:38] @description requires a value[C:\Users\athma\Downloads\CPP527\Week 3\montyhall\R\monty-hall-problem.R:39] @details requires a value[C:\Users\athma\Downloads\CPP527\Week 3\montyhall\R\monty-hall-problem.R:40] @param requires a value[C:\Users\athma\Downloads\CPP527\Week 3\montyhall\R\monty-hall-problem.R:42] @examples requires a value[C:\Users\athma\Downloads\CPP527\Week 3\montyhall\R\monty-hall-problem.R:54] @description requires a value[C:\Users\athma\Downloads\CPP527\Week 3\montyhall\R\monty-hall-problem.R:55] @details requires a value[C:\Users\athma\Downloads\CPP527\Week 3\montyhall\R\monty-hall-problem.R:56] @param requires a value[C:\Users\athma\Downloads\CPP527\Week 3\montyhall\R\monty-hall-problem.R:58] @examples requires a value[C:\Users\athma\Downloads\CPP527\Week 3\montyhall\R\monty-hall-problem.R:80] @description requires a value[C:\Users\athma\Downloads\CPP527\Week 3\montyhall\R\monty-hall-problem.R:81] @details requires a value[C:\Users\athma\Downloads\CPP527\Week 3\montyhall\R\monty-hall-problem.R:82] @param requires a value[C:\Users\athma\Downloads\CPP527\Week 3\montyhall\R\monty-hall-problem.R:84] @examples requires a value[C:\Users\athma\Downloads\CPP527\Week 3\montyhall\R\monty-hall-problem.R:105] @description requires a value[C:\Users\athma\Downloads\CPP527\Week 3\montyhall\R\monty-hall-problem.R:106] @details requires a value[C:\Users\athma\Downloads\CPP527\Week 3\montyhall\R\monty-hall-problem.R:107] @param requires a value[C:\Users\athma\Downloads\CPP527\Week 3\montyhall\R\monty-hall-problem.R:109] @examples requires a value[C:\Users\athma\Downloads\CPP527\Week 3\montyhall\R\monty-hall-problem.R:128] @description requires a value[C:\Users\athma\Downloads\CPP527\Week 3\montyhall\R\monty-hall-problem.R:129] @details requires a value[C:\Users\athma\Downloads\CPP527\Week 3\montyhall\R\monty-hall-problem.R:130] @param requires a value[C:\Users\athma\Downloads\CPP527\Week 3\montyhall\R\monty-hall-problem.R:132] @examples requires a value[C:\Users\athma\Downloads\CPP527\Week 3\montyhall\R\monty-hall-problem.R:159] @description requires a value[C:\Users\athma\Downloads\CPP527\Week 3\montyhall\R\monty-hall-problem.R:160] @details requires a value[C:\Users\athma\Downloads\CPP527\Week 3\montyhall\R\monty-hall-problem.R:161] @param requires a value[C:\Users\athma\Downloads\CPP527\Week 3\montyhall\R\monty-hall-problem.R:163] @examples requires a valueWriting NAMESPACE Writing NAMESPACE

And when I ran this

setwd( ".." )
devtools::install( "montyhall" )

Error: Can't find 'C:\Users\athma\Downloads\CPP527\montyhall'.

What am I doing wrong?

imanprs commented 3 years ago

Hi @malmufre, Let me jump in maybe I can help before Prof. Lecy sees your question.

Regarding the working directory, the instructions assume that the directory is not reset anywhere along the way. When you run setwd( ".." ) you're simply going up one level in your directory, but since, apparently, you already reset to C:/Users/athma/Downloads/CPP527/Week 3/, it takes you to the CPP527 folder where you do not have a folder named "montyhall" which is the folder containing the package files.

So you either have to drop the root.dir option or not use setwd( ".." ) at this point.

lecy commented 3 years ago

What @imanprs suggests here is exactly right.

If you are working in RMD documents then make the following substitutions:

# replace
setwd( "montyhall" )
# with
setwd( "C:/Users/athma/Downloads/CPP527/Week 3/montyhall" )

# replace
setwd( ".." )
# with
setwd( "C:/Users/athma/Downloads/CPP527/Week 3" )
malmufre commented 3 years ago

@lecy @imanprs Thank you for your help . I am still getting the same error. I have even started a new RMD and started all over. When I run this:


setwd( "C:/Users/athma/OneDrive/Documents/montyhall" )
devtools::document()

I get: Show in New WindowClear OutputExpand/Collapse Output Loading required package: usethis

Attaching package: �testthat�

The following object is masked from �package:devtools�:

test_file

Show in New WindowClear OutputExpand/Collapse Output Your system is ready to build packages! Show in New WindowClear OutputExpand/Collapse Output v Setting active project to 'C:/Users/athma/OneDrive/Documents/montyhall' v Leaving 'DESCRIPTION' unchanged Package: montyhall Title: What the Package Does (One Line, Title Case) Version: 0.0.0.9000 Authors@R (parsed):

-- Conflicts -------------------------------------------- montyhall conflicts -- x change_door() masks montyhall::change_door() x create_game() masks montyhall::create_game() x determine_winner() masks montyhall::determine_winner() ... and 4 more

Did you accidentally source a file rather than using load_all()? Run rm(list = c("change_door", "create_game", "determine_winner", "open_goat_door", "play_game", "play_n_games", "select_door")) to remove the conflicts.[C:\Users\athma\OneDrive\Documents\montyhall\R\monty-hall-problem.R:38] @description requires a value[C:\Users\athma\OneDrive\Documents\montyhall\R\monty-hall-problem.R:39] @details requires a value[C:\Users\athma\OneDrive\Documents\montyhall\R\monty-hall-problem.R:40] @param requires a value[C:\Users\athma\OneDrive\Documents\montyhall\R\monty-hall-problem.R:42] @examples requires a value[C:\Users\athma\OneDrive\Documents\montyhall\R\monty-hall-problem.R:54] @description requires a value[C:\Users\athma\OneDrive\Documents\montyhall\R\monty-hall-problem.R:55] @details requires a value[C:\Users\athma\OneDrive\Documents\montyhall\R\monty-hall-problem.R:56] @param requires a value[C:\Users\athma\OneDrive\Documents\montyhall\R\monty-hall-problem.R:58] @examples requires a value[C:\Users\athma\OneDrive\Documents\montyhall\R\monty-hall-problem.R:80] @description requires a value[C:\Users\athma\OneDrive\Documents\montyhall\R\monty-hall-problem.R:81] @details requires a value[C:\Users\athma\OneDrive\Documents\montyhall\R\monty-hall-problem.R:82] @param requires a value[C:\Users\athma\OneDrive\Documents\montyhall\R\monty-hall-problem.R:84] @examples requires a value[C:\Users\athma\OneDrive\Documents\montyhall\R\monty-hall-problem.R:105] @description requires a value[C:\Users\athma\OneDrive\Documents\montyhall\R\monty-hall-problem.R:106] @details requires a value[C:\Users\athma\OneDrive\Documents\montyhall\R\monty-hall-problem.R:107] @param requires a value[C:\Users\athma\OneDrive\Documents\montyhall\R\monty-hall-problem.R:109] @examples requires a value[C:\Users\athma\OneDrive\Documents\montyhall\R\monty-hall-problem.R:128] @description requires a value[C:\Users\athma\OneDrive\Documents\montyhall\R\monty-hall-problem.R:129] @details requires a value[C:\Users\athma\OneDrive\Documents\montyhall\R\monty-hall-problem.R:130] @param requires a value[C:\Users\athma\OneDrive\Documents\montyhall\R\monty-hall-problem.R:132] @examples requires a value[C:\Users\athma\OneDrive\Documents\montyhall\R\monty-hall-problem.R:159] @description requires a value[C:\Users\athma\OneDrive\Documents\montyhall\R\monty-hall-problem.R:160] @details requires a value[C:\Users\athma\OneDrive\Documents\montyhall\R\monty-hall-problem.R:161] @param requires a value[C:\Users\athma\OneDrive\Documents\montyhall\R\monty-hall-problem.R:163] @examples requires a valueWriting NAMESPACE Writing NAMESPACE

and then I am getting this:

setwd( "C:/Users/athma/OneDrive/Documents/montyhall" )

devtools::install( "montyhall" )

Error: Can't find 'C:\Users\athma\OneDrive\Documents\montyhall\montyhall

lecy commented 3 years ago

It would be:

setwd( "C:/Users/athma/OneDrive/Documents" )
devtools::install( "montyhall" )

NOT:

setwd( "C:/Users/athma/OneDrive/Documents/montyhall" )
devtools::install( "montyhall" )

For the previous steps you are working inside of the montyhall folder, but when you install the package you need to be one level above, in the documents folder that contains that directory. Thus the setwd( ".." ) to go a level up, but because the directory location resets to the default after each chunk in R Studio you would have to reference the full path in that chunk.

For the other errors, you might need to delete the montyhall folder and start over if you ran into issue in the middle of the install.

malmufre commented 3 years ago

I have changed it and got this:

setwd( "C:/Users/athma/OneDrive/Documents" )

devtools::install( "montyhall" )

√ checking for file 'C:\Users\athma\OneDrive\Documents\montyhall/DESCRIPTION' (520ms)

Running "C:/PROGRA~1/R/R-40~1.2/bin/x64/Rcmd.exe" INSTALL \ "C:\Users\athma\AppData\Local\Temp\RtmpuOz4cX/montyhall_0.0.0.9000.tar.gz" \ --install-tests

Error: System command 'Rcmd.exe' failed, exit status: 1, stdout & stderr were printed

Stack trace:

  1. devtools::install("montyhall")
  2. pkgbuild::with_build_tools(required = FALSE, callr::rcmd("IN ...
  3. withr::with_path(rtools_path(), code)
  4. base:::force(code)
  5. callr::rcmd("INSTALL", c(install_path, opts), echo = !quiet, ...
  6. callr:::run_r(options)
  7. base:::with(options, with_envvar(env, do.call(processx::run, ...
  8. base:::with.default(options, with_envvar(env, do.call(proces ...
  9. base:::eval(substitute(expr), data, enclos = parent.frame())
  10. base:::eval(substitute(expr), data, enclos = parent.frame())
  11. callr:::with_envvar(env, do.call(processx::run, c(list(bin, ...
  12. base:::force(code)
  13. base:::do.call(processx::run, c(list(bin, args = real_cmdarg ...
  14. (function (command = NULL, args = character(), error_on_stat ...
  15. throw(new_process_error(res, call = sys.call(), echo = echo, ...

    x System command 'Rcmd.exe' failed, exit status: 1, stdout & stderr were printed

Error in (function (command = NULL, args = character(), error_on_status = TRUE, : System command 'Rcmd.exe' failed

Is that okay?

As for the other errors is it fine if I got

Writing create_game.Rd Writing select_door.Rd Writing open_goat_door.Rd Writing change_door.Rd Writing determine_winner.Rd Writing play_game.Rd Writing play_n_games.Rd

but with all the other errors appearing?

Thanks!

lecy commented 3 years ago

It looks like an error in the Roxygen documentation for change_door(). I would check your file to see what you have for the title field:

#' @title
#' @description
#' @details
#' @param 
#' @return 
#' @examples
#' @export
change_door <- function( stay=T, opened.door, a.pick )
{
   doors <- c(1,2,3) 

   if( stay )
   {
     final.pick <- a.pick
   }
   if( ! stay )
   {
     final.pick <- doors[ doors != opened.door & doors != a.pick ] 
   }

   return( final.pick )  # number between 1 and 3
}
malmufre commented 3 years ago

I still have not written anything in the R script so it's exactly as the one provided . Do you suggest I add descriptions and see if I still get errors?

lecy commented 3 years ago

Yes, you need to complete the Roxygen fields before running the step that generates the documentation.

If you skipped that step and are trying to install the package that might be the source of the error.

malmufre commented 3 years ago

@lecy After I filled my Roxygen fields. I managed to get the package to work. I also tested it. However, I am still getting this when I run

setwd( "C:/Users/athma/Downloads/CPP527/Week 4/montyhall" )
devtools::document()

The working directory was changed to C:/Users/athma/Downloads/CPP527/Week 4/montyhall inside a notebook chunk. The working directory will be reset when the chunk is finished running. Use the knitr root.dir option in the setup chunk to change the working directory for notebook chunks.Updating montyhall documentation Loading montyhall Writing NAMESPACE Writing NAMESPACE Writing open_goat_door.Rd Writing change_door.Rd Writing determine_winner.Rd Writing play_n_games.Rd

I didn't get the first part.

JasonSills commented 3 years ago

Hi @lecy,

I'm at the stage where I'm testing my functions. I'm not quite sure what values to put into some of the functions. For example, open_goat_door(). The function is game and a.pick. I thought this would be passing through some values, but it doesn't seem to work.

open_goat_door(game = "'goat', 'car',  'goat'", a.pick = 1)
returns
Error in open_goat_door(game = "'goat', 'car',  'goat'", a.pick = 1) : 
  object 'opened.door' not found

I've tried a few different iterations, but nothing is working. What do I enter in the function to test these?

Thank you!

lecy commented 3 years ago

Remember to always use the c() function when passing groups of argument. You are using quotes:

# open_goat_door( game = "'goat', 'car',  'goat'", a.pick = 1 )
open_goat_door( game = c('goat', 'car',  'goat'), a.pick = 1 )
lecy commented 3 years ago

@malmufre That looks like it worked.

This is just saying that it will change the directory back to the default after finishing the chunk unless you change it using the root directory argument in knitr.

The working directory was changed to C:/Users/athma/Downloads/CPP527/Week 4/montyhall inside a notebook chunk. The working directory will be reset when the chunk is finished running. Use the knitr root.dir option in the setup chunk to change the working directory for notebook chunks.

MeghanPaquette commented 3 years ago

Error in first steps: Specifically - ✔ Writing 'montyhall.Rproj'

I installed the libraries/packages as listed. Tested Dev Tools as suggested and everything seems to work. I have tried to save the working directory to my desktop and to documents, but location doesn't seem to matter. The code stops matching the information in the instructions and only the NAMESPACE and DESCRIPTION are loading into the folder, vs the other information. I have googled, but I don't seem to see what I am missing.

I am doing this in R, should I be doing it in R studio?

> library(devtools)
Loading required package: usethis
> has_devel()
Your system is ready to build packages!
> setwd('/Users/mpaquette/Documents')
> usethis::create_package("montyhall")
✔ Creating 'montyhall/'
✔ Setting active project to '/Users/mpaquette/Documents/montyhall'
✔ Creating 'R/'
✔ Writing 'DESCRIPTION'
Package: montyhall
Title: What the Package Does (One Line, Title Case)
Version: 0.0.0.9000
Authors@R (parsed):
    * First Last <first.last@example.com> [aut, cre] (YOUR-ORCID-ID)
Description: What the package does (one paragraph).
License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a
    license
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1
✔ Writing 'NAMESPACE'
✔ Changing working directory to 'montyhall/'
Error: Directory 'montyhall' does not exist.
✔ Setting active project to '<no active project>'
> 
lecy commented 3 years ago

@MeghanPaquette If it is unable to create a new directory on your computer that suggests there may be some permission problems. Do you have admin controls on your computer?

Can you report your session info when attempting this step, please:

sessionInfo()

Does this work?

dir.create( "testdir" )

You should see a new folder called "testdir".

MeghanPaquette commented 3 years ago

@MeghanPaquette If it is unable to create a new directory on your computer that suggests there may be some permission problems. Do you have admin controls on your computer?

Hi Dr. Lecy @lecy , it is my personal computer, so I should have admin controls. I ran the session info as you suggested and that is what printed out. When I tried the dir.create( "testdir" ) function, it created a testdir folder in the montyhall folder location.

> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.6

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] devtools_2.3.2 usethis_1.6.3 

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4.6      rstudioapi_0.11   xml2_1.3.2        knitr_1.29       
 [5] magrittr_1.5      roxygen2_7.1.1    pkgload_1.1.0     R6_2.4.1         
 [9] rlang_0.4.7       fansi_0.4.1       stringr_1.4.0     tools_4.0.2      
[13] pkgbuild_1.1.0    xfun_0.17         sessioninfo_1.1.1 cli_2.0.2        
[17] git2r_0.27.1      withr_2.2.0       ellipsis_0.3.1    remotes_2.2.0    
[21] assertthat_0.2.1  digest_0.6.25     rprojroot_1.3-2   crayon_1.3.4     
[25] processx_3.4.2    purrr_0.3.4       callr_3.4.4       fs_1.4.1         
[29] ps_1.3.3          testthat_2.3.2    memoise_1.1.0     glue_1.4.0       
[33] stringi_1.4.6     compiler_4.0.2    desc_1.2.0        backports_1.1.8  
[37] prettyunits_1.1.1
> dir.create("testdir")
> 
> 

2F98232A-58A4-4E6A-B12B-B98C520E3BAC

Niagara1000 commented 3 years ago

@lecy After I filled my Roxygen fields. I managed to get the package to work. I also tested it. However, I am still getting this when I run

setwd( "C:/Users/athma/Downloads/CPP527/Week 4/montyhall" )
devtools::document()

The working directory was changed to C:/Users/athma/Downloads/CPP527/Week 4/montyhall inside a notebook chunk. The working directory will be reset when the chunk is finished running. Use the knitr root.dir option in the setup chunk to change the working directory for notebook chunks.Updating montyhall documentation Loading montyhall Writing NAMESPACE Writing NAMESPACE Writing open_goat_door.Rd Writing change_door.Rd Writing determine_winner.Rd Writing play_n_games.Rd

I didn't get the first part.

@malmufre I'm not sure exactly what was the issue here, but I do know that if filenames and filepaths have spaces in them, I generally get errors. I recommend changing the part of the filepath where you have 'Week 4' to 'Week_4' or simply 'Week4'.

lecy commented 3 years ago

@MeghanPaquette It looks like the montyhall directory was created fine, though? It has the R folder, NAMESPACE, and DESCRIPTION files - those are all you need from the first step.

Are you running inside of a chunk in R Studio or in a regular R console - running outside of R Studio might solve some of the directory problems.

Did you try moving on to the next step?

MeghanPaquette commented 3 years ago

@lecy - Yes, I was running it in the R Console, but the errors still happened. I did try moving on to the next step and it seemed to work and my package loaded on my computer and ran. Fingers crossed it holds up to your tests :)