Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deal <- function(cards) in 6.2 Deal a Card #66

Open
soumyakde opened this issue Jan 16, 2023 · 2 comments
Open

deal <- function(cards) in 6.2 Deal a Card #66

soumyakde opened this issue Jan 16, 2023 · 2 comments

Comments

@soumyakde
Copy link

I am a beginner and 'am very impressed with the book's method of teaching. I think it would help if you explained why you used function(cards), as "cards" itself was not defined as a variable before this use
deal <- function(cards) {

?

}
and followed by...
deal <- function(cards) {
cards[1, ]
}
For e.g. if we run > deal(), gives the following error...
Error in deal() : argument "cards" is missing, with no default

@davidrsch
Copy link

davidrsch commented Jan 16, 2023

Hello,
When creating a function the arguments of it are defined between parentheses separated by commas. For example:

sum2num <- function (x, y){
   x + y
}

This function expect two arguments to work with and add them together, x and y doesn't have to be defined previously to use the function. But if they are not defined previously you must defined them when calling the sum2num function or you will get an error:

sum2num()
##   Error in sum2num(): argument "x" is missing, with no default

The proper way to use this function is defining the arguments when calling it:

sum2num(x=1, y=2)
##   [1] 3

So, you may already notice why are you getting an error, you must give a value to the argument cards of the deal function when calling the function:

deal(cards = deck)

(Note: The previous solution assume you have created the deck object)

@soumyakde
Copy link
Author

soumyakde commented Jan 16, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants