From fd4a2bf311cd273c63d7564b11df71838b2f50af Mon Sep 17 00:00:00 2001 From: BradXPS_Kraken Date: Fri, 1 Nov 2019 21:13:33 -0500 Subject: [PATCH 1/3] Preppring for 0.2.3 quickfix release --- DESCRIPTION | 3 +- NEWS.md | 6 ++- R/getQuickstat.R | 68 +++++++++++++------------------ R/plotting.R | 18 ++++---- docs/404.html | 2 +- docs/LICENSE-text.html | 2 +- docs/articles/index.html | 2 +- docs/articles/using_tidyusda.html | 4 +- docs/authors.html | 2 +- docs/index.html | 2 +- docs/news/index.html | 14 ++++++- docs/reference/allCategory.html | 2 +- docs/reference/allCommodity.html | 2 +- docs/reference/allCounty.html | 2 +- docs/reference/allDataItem.html | 2 +- docs/reference/allDomain.html | 2 +- docs/reference/allGeogLevel.html | 2 +- docs/reference/allGroup.html | 2 +- docs/reference/allProgram.html | 2 +- docs/reference/allSector.html | 2 +- docs/reference/allState.html | 2 +- docs/reference/getQuickstat.html | 2 +- docs/reference/index.html | 2 +- docs/reference/plotUSDA.html | 2 +- docs/reference/reexports.html | 2 +- docs/reference/tidyUSDA.html | 2 +- vignettes/using_tidyusda.Rmd | 2 +- 27 files changed, 82 insertions(+), 73 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index bdc50c6..7dd5e95 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -38,7 +38,8 @@ Imports: sf, stringi, tigris, - usethis + usethis, + crayon Suggests: knitr, rgeos, diff --git a/NEWS.md b/NEWS.md index bcc4240..848e6a9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,8 @@ -# tidyUSDA (development version) +# tidyUSDA + +# tidyUSDA 0.2.3 +* Fixed interacting plotting issue with builds +* Added crayon highlighting to error trapping code # tidyUSDA 0.2.2 * Added messages for macOS users before they try plotUSDA (graphics issue with underlying geom_sf()) diff --git a/R/getQuickstat.R b/R/getQuickstat.R index 5bf9a91..e805d1d 100644 --- a/R/getQuickstat.R +++ b/R/getQuickstat.R @@ -294,7 +294,7 @@ getQuickstat <- function(key=NULL, program=NULL, data_item=NULL, sector=NULL, gr # Install rgeos if not already installed if (!"rgeos" %in% utils::installed.packages()) { - stop("Package \"rgeos\" needed for this function to work. Please install it with install.packages(\"rgeos\")", + stop(crayon::cyan("Package \"rgeos\" needed for this function to work. Please install it with install.packages(\"rgeos\")"), call. = FALSE) } @@ -302,71 +302,71 @@ if (!"rgeos" %in% utils::installed.packages()) { # Key if(is.null(key)){ - message("API key missing; enter an API key.") + message(crayon::cyan("API key missing; enter an API key.")) } # Program if(is.null(program)){} else if(!toupper(program) %in% tidyUSDA::allProgram){ - recommendation <- fuzzyMatch(toupper(program), tidyUSDA::allProgram); - message(paste0("Your value for PROGRAM is not valid. Did you mean ", + recommendation <- crayon::red(fuzzyMatch(toupper(program), tidyUSDA::allProgram)); + message(crayon::cyan(paste0("Your value for PROGRAM is not valid. Did you mean ", recommendation, - "? If not, check tidyUSDA::allProgram for a vector of all acceptable values.")) + "? If not, check tidyUSDA::allProgram for a vector of all acceptable values."))) } # Data item if(is.null(data_item)){} else if(!toupper(data_item) %in% tidyUSDA::allDataItem){ - recommendation <- fuzzyMatch(toupper(data_item), tidyUSDA::allDataItem); - message(paste0("Your value for DATA_ITEM is not valid. Did you mean ", + recommendation <- crayon::red(fuzzyMatch(toupper(data_item), tidyUSDA::allDataItem)); + message(crayon::cyan(paste0("Your value for DATA_ITEM is not valid. Did you mean ", recommendation, - "? If not, check tidyUSDA::allDataItem for a vector of all acceptable values.")) + "? If not, check tidyUSDA::allDataItem for a vector of all acceptable values."))) } # Sector if(is.null(sector)){} else if (!is.null(sector) & !toupper(sector) %in% tidyUSDA::allSector){ - recommendation <- fuzzyMatch(toupper(sector), tidyUSDA::allSector); - message(paste0("Your value for SECTOR is not valid. Did you mean ", + recommendation <- crayon::red(fuzzyMatch(toupper(sector), tidyUSDA::allSector)); + message(crayon::cyan(paste0("Your value for SECTOR is not valid. Did you mean ", recommendation, - "? If not, check tidyUSDA::allSector for a vector of all acceptable values.")) + "? If not, check tidyUSDA::allSector for a vector of all acceptable values."))) } # Group if(is.null(group)){} else if(!toupper(group) %in% tidyUSDA::allGroup){ - recommendation <- fuzzyMatch(toupper(group), tidyUSDA::allGroup); - message(paste0("Your value for GROUP is not valid. Did you mean ", + recommendation <- crayon::red(fuzzyMatch(toupper(group), tidyUSDA::allGroup)); + message(crayon::cyan(paste0("Your value for GROUP is not valid. Did you mean ", recommendation, - "? If not, check tidyUSDA::allGroup for a vector of all acceptable values.")) + "? If not, check tidyUSDA::allGroup for a vector of all acceptable values."))) } # Commodity if(is.null(commodity)){} else if(!toupper(commodity) %in% tidyUSDA::allCommodity){ - recommendation <- fuzzyMatch(toupper(commodity), tidyUSDA::allCommodity); - message(paste0("Your value for COMMODITY is not valid. Did you mean ", + recommendation <- crayon::red(fuzzyMatch(toupper(commodity), tidyUSDA::allCommodity)); + message(crayon::cyan(paste0("Your value for COMMODITY is not valid. Did you mean ", recommendation, - "? If not, check tidyUSDA::allCommodity for a vector of all acceptable values.")) + "? If not, check tidyUSDA::allCommodity for a vector of all acceptable values."))) } # Category if(is.null(category)){} else if(!toupper(category) %in% tidyUSDA::allCategory){ - recommendation <- fuzzyMatch(toupper(category), tidyUSDA::allCategory); - message(paste0("Your value for CATEGORY is not valid. Did you mean ", + recommendation <- crayon::red(fuzzyMatch(toupper(category), tidyUSDA::allCategory)); + message(crayon::cyan(paste0("Your value for CATEGORY is not valid. Did you mean ", recommendation, - "? If not, check tidyUSDA::allCategory for a vector of all acceptable values.")) + "? If not, check tidyUSDA::allCategory for a vector of all acceptable values."))) } # Domain if(is.null(domain)){} else if(!toupper(domain) %in% tidyUSDA::allDomain){ - recommendation <- fuzzyMatch(toupper(domain), tidyUSDA::allDomain); - message(paste0("Your value for DOMAIN is not valid. Did you mean ", + recommendation <- crayon::red(fuzzyMatch(toupper(domain), tidyUSDA::allDomain)); + message(crayon::cyan(paste0("Your value for DOMAIN is not valid. Did you mean ", recommendation, - "? If not, check tidyUSDA::allDomain for a vector of all acceptable values.")) + "? If not, check tidyUSDA::allDomain for a vector of all acceptable values."))) } # Geographic level if(is.null(geographic_level)){} else if(!toupper(geographic_level) %in% tidyUSDA::allGeogLevel){ - recommendation <- fuzzyMatch(toupper(geographic_level), tidyUSDA::allGeogLevel); - message(paste0("Your value for GEOGRAPHIC_LEVEL is not valid. Did you mean ", + recommendation <- crayon::red(fuzzyMatch(toupper(geographic_level), tidyUSDA::allGeogLevel)); + message(crayon::cyan(paste0("Your value for GEOGRAPHIC_LEVEL is not valid. Did you mean ", recommendation, - "? If not, check tidyUSDA::allGeogLevel for a vector of all acceptable values.")) + "? If not, check tidyUSDA::allGeogLevel for a vector of all acceptable values."))) } @@ -403,19 +403,9 @@ if (!"rgeos" %in% utils::installed.packages()) { state=state, county=county, year=year, geometry = geometry, lower48 = lower48) } - # Reset variables to a default value if not used - # if(is.null(program)){program <- 'NON'} - # if(is.null(sector)){sector <- 'NON'} - # if(is.null(group)){group <- 'NON'} - # if(is.null(commodity)){commodity <- 'NON'} - # if(is.null(category)){category <- 'NON'} - # if(is.null(data_item)){data_item <- 'NON'} - # if(is.null(domain)){domain <- 'NON'} + if(is.null(geographic_level)){geographic_level <- 'NON'} - # if(is.null(state)){state <- 'NON'} - # if(is.null(county)){county <- 'NON'} - # if(is.null(year)){year <- 'NON'} - # + # STATE if(geometry & geographic_level == 'STATE'){ @@ -462,6 +452,6 @@ if (!"rgeos" %in% utils::installed.packages()) { return(mydata) } - + diff --git a/R/plotting.R b/R/plotting.R index 1f58aee..bb64b63 100644 --- a/R/plotting.R +++ b/R/plotting.R @@ -20,24 +20,27 @@ plotUSDA <- function(df, fill_by = 'Value'){ + # Install rgeos if not already installed if (!"rgeos" %in% utils::installed.packages()) { - stop("Package \"rgeos\" needed for this function to work. Please install it with install.packages(\"rgeos\")", + stop(crayon::cyan("Package \"rgeos\" needed for this function to work. Please install it with install.packages(\"rgeos\")"), call. = FALSE) } # Logic to warn if using Mac OsX - issue with plotting - mac <- FALSE + quartz <- FALSE stopit <- FALSE - if(stringi::stri_detect(str = utils::osVersion, regex = "mac")) {mac <- TRUE} - if(mac) { + + + if(identical(getOption("bitmapType"), "quartz")) {quartz <- TRUE} + if(quartz) { - stopit <- usethis::ui_yeah("It appears you are using Mac. Mac OsX has a graphics device that doesn't handle the underlying ggplot2::geom_sf() very well. We recommend you use a package like tmap or leaflet to plot this dataframe. You can still use plotUSDA, it will just take 10 minutes possibly. Do you want to skip plotting using plotUSDA?") + stopit <- message(cat(crayon::cyan("It appears your session is using a", crayon::red("quartz graphics device"), crayon::cyan("- probably macOS. The quartz graphics device doesn't handle the underlying ggplot2::geom_sf() very well. We recommend you either switch to another device, like X11, or use a package like tmap or leaflet to plot this dataframe. You can still use plotUSDA with quartz, it just may take 10 minutes.")))) + + # if(stopit) {message("Quitting, gonna try another mapping package like tmap or leaflet.")} } - if(stopit) {stop("Quitting since using Mac, gonna try another mapping package like tmap or leaflet.")} - z <- ggplot2::ggplot(df) + ggplot2::geom_sf(ggplot2::aes_string(fill = fill_by)) + ggplot2::coord_sf(datum=NA) + @@ -49,3 +52,4 @@ plotUSDA <- function(df, fill_by = 'Value'){ } + diff --git a/docs/404.html b/docs/404.html index 6f12cdb..367a568 100644 --- a/docs/404.html +++ b/docs/404.html @@ -76,7 +76,7 @@ tidyUSDA - 0.2.2 + 0.2.2.9000 diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index ab74f9d..268906d 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -76,7 +76,7 @@ tidyUSDA - 0.2.2 + 0.2.2.9000 diff --git a/docs/articles/index.html b/docs/articles/index.html index e73cb6c..24a37b1 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -76,7 +76,7 @@ tidyUSDA - 0.2.2 + 0.2.2.9000 diff --git a/docs/articles/using_tidyusda.html b/docs/articles/using_tidyusda.html index bba3c7c..41814e8 100644 --- a/docs/articles/using_tidyusda.html +++ b/docs/articles/using_tidyusda.html @@ -38,7 +38,7 @@ tidyUSDA - 0.2.2 + 0.2.2.9000 @@ -162,7 +162,7 @@

-

Note: it is a known issue that the RStudio graphics device on Mac Os X can be extremely laggy when plotting. To get around this, feel free to use your own plotting methods such as the tmap package or leaflet.

+

Note: it is a known issue that the RStudio graphics device on macOS can be extremely laggy when plotting. To get around this, feel free to use your own plotting methods such as the tmap package or leaflet.

OK wow so it looks like all the farms in the country are in California. But wait a second, California is huge as far as landmass, and the relative size of the farms are smaller on balance, so maybe we should look at this a different way. First let’s clean up the dataframe so it’s easier to work with.

mydata <- ops.with.sales[,c("NAME", "Value", "ALAND")]

We select the name of the state, the value from our Quick Stat query (number of ops) and ‘ALAND’, which is the land area in square meters. Let’s modify our dataframe to calculate the number of operations per square meter, so the size of the state doesn’t affect what we’re trying to derive.

diff --git a/docs/authors.html b/docs/authors.html index 70b6a90..36f4bd9 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -76,7 +76,7 @@ tidyUSDA - 0.2.2 + 0.2.2.9000 diff --git a/docs/index.html b/docs/index.html index 1e97c81..4debac9 100644 --- a/docs/index.html +++ b/docs/index.html @@ -43,7 +43,7 @@ tidyUSDA - 0.2.2 + 0.2.2.9000 diff --git a/docs/news/index.html b/docs/news/index.html index cb5df4c..e79a765 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -76,7 +76,7 @@ tidyUSDA - 0.2.2 + 0.2.2.9000 @@ -131,9 +131,18 @@

Changelog

Source: NEWS.md +
+

+tidyUSDA 0.2.3 Unreleased +

+ +

-tidyUSDA 0.2.2 Unreleased +tidyUSDA 0.2.2 2019-10-28

diff --git a/docs/reference/allCounty.html b/docs/reference/allCounty.html index 7b8f76a..f074739 100644 --- a/docs/reference/allCounty.html +++ b/docs/reference/allCounty.html @@ -77,7 +77,7 @@ tidyUSDA - 0.2.2 + 0.2.2.9000 diff --git a/docs/reference/allDataItem.html b/docs/reference/allDataItem.html index b203b52..bd16a19 100644 --- a/docs/reference/allDataItem.html +++ b/docs/reference/allDataItem.html @@ -77,7 +77,7 @@ tidyUSDA - 0.2.2 + 0.2.2.9000 diff --git a/docs/reference/allDomain.html b/docs/reference/allDomain.html index 21bbcb8..d69db91 100644 --- a/docs/reference/allDomain.html +++ b/docs/reference/allDomain.html @@ -77,7 +77,7 @@ tidyUSDA - 0.2.2 + 0.2.2.9000 diff --git a/docs/reference/allGeogLevel.html b/docs/reference/allGeogLevel.html index f62f4fc..a8eddea 100644 --- a/docs/reference/allGeogLevel.html +++ b/docs/reference/allGeogLevel.html @@ -77,7 +77,7 @@ tidyUSDA - 0.2.2 + 0.2.2.9000 diff --git a/docs/reference/allGroup.html b/docs/reference/allGroup.html index ebefd19..adb1331 100644 --- a/docs/reference/allGroup.html +++ b/docs/reference/allGroup.html @@ -77,7 +77,7 @@ tidyUSDA - 0.2.2 + 0.2.2.9000 diff --git a/docs/reference/allProgram.html b/docs/reference/allProgram.html index e3ce89e..5669ecb 100644 --- a/docs/reference/allProgram.html +++ b/docs/reference/allProgram.html @@ -77,7 +77,7 @@ tidyUSDA - 0.2.2 + 0.2.2.9000 diff --git a/docs/reference/allSector.html b/docs/reference/allSector.html index 35821a7..fa87a87 100644 --- a/docs/reference/allSector.html +++ b/docs/reference/allSector.html @@ -77,7 +77,7 @@ tidyUSDA - 0.2.2 + 0.2.2.9000 diff --git a/docs/reference/allState.html b/docs/reference/allState.html index 32ba697..a0a7ed1 100644 --- a/docs/reference/allState.html +++ b/docs/reference/allState.html @@ -77,7 +77,7 @@ tidyUSDA - 0.2.2 + 0.2.2.9000 diff --git a/docs/reference/getQuickstat.html b/docs/reference/getQuickstat.html index 336e73d..a7e4113 100644 --- a/docs/reference/getQuickstat.html +++ b/docs/reference/getQuickstat.html @@ -78,7 +78,7 @@ tidyUSDA - 0.2.2 + 0.2.2.9000 diff --git a/docs/reference/index.html b/docs/reference/index.html index d348ddf..7560b36 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -76,7 +76,7 @@ tidyUSDA - 0.2.2 + 0.2.2.9000 diff --git a/docs/reference/plotUSDA.html b/docs/reference/plotUSDA.html index 46296b3..9e82b01 100644 --- a/docs/reference/plotUSDA.html +++ b/docs/reference/plotUSDA.html @@ -77,7 +77,7 @@ tidyUSDA - 0.2.2 + 0.2.2.9000 diff --git a/docs/reference/reexports.html b/docs/reference/reexports.html index 93a74a1..11c6770 100644 --- a/docs/reference/reexports.html +++ b/docs/reference/reexports.html @@ -82,7 +82,7 @@ tidyUSDA - 0.2.2 + 0.2.2.9000 diff --git a/docs/reference/tidyUSDA.html b/docs/reference/tidyUSDA.html index 076b000..3ff3f3d 100644 --- a/docs/reference/tidyUSDA.html +++ b/docs/reference/tidyUSDA.html @@ -77,7 +77,7 @@ tidyUSDA - 0.2.2 + 0.2.2.9000 diff --git a/vignettes/using_tidyusda.Rmd b/vignettes/using_tidyusda.Rmd index 2792729..e576e9b 100644 --- a/vignettes/using_tidyusda.Rmd +++ b/vignettes/using_tidyusda.Rmd @@ -98,7 +98,7 @@ tidyUSDA::plotUSDA(df = ops.with.sales) ``` -*Note: it is a known issue that the RStudio graphics device on Mac Os X can be extremely laggy when plotting. To get around this, feel free to use your own plotting methods such as the [tmap](https://github.com/mtennekes/tmap) package or [leaflet](https://rstudio.github.io/leaflet/).* +*Note: it is a known issue that the RStudio graphics device on macOS can be extremely laggy when plotting. To get around this, feel free to use your own plotting methods such as the [tmap](https://github.com/mtennekes/tmap) package or [leaflet](https://rstudio.github.io/leaflet/).* OK wow so it looks like all the farms in the country are in California. But wait a second, California is huge as far as landmass, and the relative size of the farms are smaller on balance, so maybe we should look at this a different way. First let's clean up the dataframe so it's easier to work with. From 7ede5635c661d624ff2e19ceadceb22981c8a8fe Mon Sep 17 00:00:00 2001 From: BradXPS_Kraken Date: Fri, 1 Nov 2019 21:14:09 -0500 Subject: [PATCH 2/3] Increment version number --- DESCRIPTION | 2 +- NEWS.md | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7dd5e95..ffd68de 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Type: Package Package: tidyUSDA Title: A Minimal Tool Set for Gathering USDA Quick Stat Data for Analysis and Visualization -Version: 0.2.2.9000 +Version: 0.2.3 Authors@R: c(person(given = "Brad", family = "Lindblad", diff --git a/NEWS.md b/NEWS.md index 848e6a9..2c7d92b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,5 @@ -# tidyUSDA +# tidyUSDA 0.2.3 + # tidyUSDA 0.2.3 * Fixed interacting plotting issue with builds From f9e030c7db06376ef7a88d26a2897d95220095d5 Mon Sep 17 00:00:00 2001 From: BradXPS_Kraken Date: Fri, 1 Nov 2019 21:16:47 -0500 Subject: [PATCH 3/3] Update cran-comments.md before submitting to CRAN --- cran-comments.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cran-comments.md b/cran-comments.md index 5a5adce..e3d1239 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,4 +1,4 @@ -Fixed a few minor bugs. +Per Prof Brian Ripley's request: the plotUSDA() function was testing for the OS, where Professor Ripley rightly pointed out that I need to test the device instead. This version fixes that. ## Test environments * local Linux Mint 19.2, R 3.6.1