ML_for_Hackers
ML_for_Hackers copied to clipboard
fast_check.R failing
I'm new to R, so I do not have a great ability to debug issues yet. After setting up the R environment on Xubuntu and OSX, I keep running into the same issues when running fast_check.R as well as the script for the first chapter.
Checking Chapter 1 - Introduction
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Error in strsplit(unitspec, " ") : non-character argument
Calls: source ... fullseq.Date -> seq -> floor_date -> parse_unit_spec -> strsplit
In addition: Warning message:
Removed 1 rows containing non-finite values (stat_bin).
Execution halted
Here's my R version: R version 3.2.3 (2015-12-10) -- "Wooden Christmas-Tree"
Is there a preferred environment/version for running the sample code, or am I really missing something?
The current code is out-of-date as R libraries have changed a lot since we released the book. We will try to update it when we have a chance.
I don't suppose you know versions that the code will run on? Could probably find a way to install old versions in the mean time.
No, but the code ran correctly when the book was released in February 2012.
I found if I change the code to :
quick.hist <- ggplot(ufo.us, aes(x = DateReported)) +
geom_histogram() + scale_x_date(date_breaks = "10 years", date_labels = "%Y")
I can get a nice plot. (with R version 3.3.1)
I have the same issue with R version 3.4.1 (2017-06-30) in x86_64-w64-mingw32 :
Error in strsplit(unitspec, " ") : non-character argument
The problem lies in the ggplot function scale_x_date. In the original code this is coded as:
quick.hist <- ggplot(ufo.us, aes(x = DateOccurred)) +
geom_histogram() +
scale_x_date(breaks = "50 years")
The breaks in scale_x_date has been adjusted to date_breaks. If you adjust the code to the following it works.
quick.hist <- ggplot(ufo.us, aes(x = DateOccurred)) +
geom_histogram() +
scale_x_date(date_breaks = "50 years", date_labels = "%Y")
In the rest of the code where you see ggplot and scale_x_date, you will have to adjust the breaks into date_breaks.