Skip to content

Instantly share code, notes, and snippets.

@garrettgman
Last active March 24, 2024 17:14
Show Gist options
  • Save garrettgman/9629323 to your computer and use it in GitHub Desktop.
Save garrettgman/9629323 to your computer and use it in GitHub Desktop.
face suit value
king spades 13
queen spades 12
jack spades 11
ten spades 10
nine spades 9
eight spades 8
seven spades 7
six spades 6
five spades 5
four spades 4
three spades 3
two spades 2
ace spades 1
king clubs 13
queen clubs 12
jack clubs 11
ten clubs 10
nine clubs 9
eight clubs 8
seven clubs 7
six clubs 6
five clubs 5
four clubs 4
three clubs 3
two clubs 2
ace clubs 1
king diamonds 13
queen diamonds 12
jack diamonds 11
ten diamonds 10
nine diamonds 9
eight diamonds 8
seven diamonds 7
six diamonds 6
five diamonds 5
four diamonds 4
three diamonds 3
two diamonds 2
ace diamonds 1
king hearts 13
queen hearts 12
jack hearts 11
ten hearts 10
nine hearts 9
eight hearts 8
seven hearts 7
six hearts 6
five hearts 5
four hearts 4
three hearts 3
two hearts 2
ace hearts 1
@Jfelipelaverde
Copy link

Hi, I am following the instructions from the book and it still imports the data, this way:

face..suit...value.
1 king,"spades",13
2 queen,"spades",12
3 jack,"spades",11
4 ten,"spades",10
5 nine,"spades",9
6 eight,"spades",8

How could I fix this?

@garrettgman
Copy link
Author

@Jfelipelaverde it seems to me that you may not be clicking the correct options in the RStudio IDE Import Data Wizard (this step), but it is hard for me to tell. Be sure that you are choosing Separator: Comma.

@ketamineabuser
Copy link

@hdshovel Click on Import Dataset in the Environment tab, then click From Text (readr)... Then paste the URL into the first field, which is the one labelled File/URL. Good luck!

Screen Shot 2019-07-31 at 11 18 54 AM

Ah, really awesome way to import a dataset. the book is fantastic.

@Svita999
Copy link

Hi, I cannot store deck and related functions into runtime environment (pages 107-110 of the book).
setup <-function(deck) {
DECK <- deck

DEAL <- function () {
card <- deck[1,]
assign ("deck", deck[-1,], envir =globalenv())
card
}
SHUFFLE <- function () {
random <- sample (1:52, size = 52)
assign ("deck", DECK[random, ], envir =globalenv())
}
}
setup
setup <-function(deck) {
DECK <- deck
DEAL <- function () {
card <- deck [1,]
assign ("deck", deck[-1,], envir =globalenv())
card
}
SHUFFLE <- function () {
random <- sample (1:52, size =52)
assign ("deck", DECK[random, ], envir =globalenv())
}
list (deal = DEAL, shuffle = SHUFFLE)
}
deal <- cards$deal
shuffle <- cards$shuffle

When I enter deal now, I get as a result NULL. When I check the environment(deal) I still get the global environment.
Please kindly help me. Thank you and best, Svita

@Santiago-2108
Copy link

Garret,
This is a phenomenal piece of literature. Your approach is top-notch. Just about every abstract concept, that would normally scare people away, was concretized. I hope this book gets the recognition it deserves. Thanks

@jsaid-delira
Copy link

Great Book! Thanks!!

@franbarbosaroyo
Copy link

Thank you. It´s a great book.

@ErdaAlexa
Copy link

Great book! Loving it xdd

@Rawlley27
Copy link

Hello, first of all, your book is excellent!

I had a doubt regarding the Exercise on Page 73 of the book where we are asked to write the shuffle function. While we do get a random card(row) on running the function deal(deck2), on running the function multiple times, I get the same card (row) again and again, is this okay or have I made a mistake?

Thank you!

@musicmind97
Copy link

The new shuffle() card isn't getting saved into a new deck. Completely normal, the author teaches you in the next couple sections the best way to go about it. Happy coding!

@Rawlley27
Copy link

The new shuffle() card isn't getting saved into a new deck. Completely normal, the author teaches you in the next couple sections the best way to go about it. Happy coding!

Thank you for the clarification!

@Rawlley27
Copy link

Hello, I had a question regarding viewing R's environment system. I installed and loaded both the usethis and the devtools package, however, when I run the function parenvs(all = TRUE), I get the error message - "Error in parenvs(all = TRUE) : could not find function "parenvs"".

Thank you!

@Rawlley27
Copy link

"Error in parenvs(all = TRUE) : could not find function "parenvs""

Okay, so it looks like that the parenvs() function has been removed from devtools, because it is now in the pryr package. Thanks!

@musicmind97
Copy link

Welcome to coding, you ask and answer a question, cause in the end they're all just a bunch of hexcodes firing around somewhere.

If you have trouble with environments, try switching your IDE. Currently I'm using PyCharm, which is a python compiler with lots of R addons, easy to use once you get the hang of it ✌

@Rawlley27
Copy link

Hello, I have a question.

As described on Page 106, when we write the following function -
deal <- function() {
card <- deck[1, ]
assign("deck", deck[-1, ], envir = globalenv())
card
}

Why is the card on top of the deck different every time we run deal( )? There has been no mention of random, as we did in the shuffle function, which would re-arrange the cards in a random order? Thank you!

@garrettgman
Copy link
Author

@Rawlley27 this line

assign("deck", deck[-1, ], envir = globalenv())

updates deck to contain everything except the top card, which has now been "dealt".

@Rawlley27
Copy link

@Rawlley27 this line

assign("deck", deck[-1, ], envir = globalenv())

updates deck to contain everything except the top card, which has now been "dealt".

Thank you for your reply! I get it now, we are getting things in order every time we run this function, queen followed by jack and so on... Thank you again for clarifying!!

@Rawlley27
Copy link

Hello, I had a question, in the following code on page 127
same <- symbols[1] == symbols[2] && symbols[2] == symbols[3]

why are there two & symbols? I know the meaning of one & but why are there two? Thank you!!

@Rawlley27
Copy link

Hello, I had a question, in the following code on page 127
same <- symbols[1] == symbols[2] && symbols[2] == symbols[3]

why are there two & symbols? I know the meaning of one & but why are there two? Thank you!!

okay, I just read the next page of the book which clarified my doubt, thank you!

@Rawlley27
Copy link

Hello, On page 134, it should be "And when cherries equal two" and not three. The cherries equal three scenario should be taken care of by Case 1 where we have three of the same symbol.

And when cherries equals three, we have:
cherries + 1

3

c(0, 2, 5)[cherries + 1]

5

I just wanted to clarify this, please do correct me if I am wrong. Thank you!

@jmh20
Copy link

jmh20 commented Jan 21, 2021

Your book really help to start R programming: smooth and progressive approach!

@menchoi
Copy link

menchoi commented Feb 16, 2021

That is great book. Thank you !

@hdshovel
Copy link

hdshovel commented Feb 18, 2021 via email

@jdfmart
Copy link

jdfmart commented Mar 20, 2021

Thank you for the book, and for making it available for free. Really appreciated.

@Gamielre
Copy link

I'm really thankful

@shaunschuyler
Copy link

Thank you for putting this together. Going through it now

@PeterHamnett
Copy link

This is a really engaging course and got me excited to learn. Thanks a lot!

@hanlu-meta
Copy link

Thank you!

@omikron41
Copy link

Muchas GRACIAS Sr. Garrett !!
El libro está BIEN PADRE e INTERESANTE, APRENDE UNO RÁPIDO... es la primera vez que aprendo a programar.
DIOS lo bendiga siempre!!
Carlos

@jose1885
Copy link

@Jfelipelaverde

Hi Felipe, I don't know if its too late, but I had a similar problem and thought that, since you have a Spanish name, like I do, our problem had something to do with the region where we are located. Indeed I found a solution. The problem is that the default separator for Spanish speaking regions is a semicolon (;), not a comma. Hence, when you download the data to Excel it will change some of the quotation marks and commas. To solve this issue you can follow the instructions in this link: https://harvestmedia.zendesk.com/hc/en-us/articles/360023978031-Opening-Excel-files-with-the-correct-CSV-list-separator#:~:text=CSV%20(comma%20delimited)%20will%20not,comma%20separator%20or%20semicolon%20separator.

I think that this may help other Spanish speaking people encountering a similar problem in the future.

I hope it helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment