@@ -423,47 +423,35 @@ stations_search <- function(name = NULL,
423423 }
424424
425425 check_int(interval )
426-
427426 stn <- dplyr :: filter(stations(),
428427 .data $ interval %in% !! interval , ! is.na(.data $ start ))
429428
429+ normals_years <- check_normals(normals_years , null_ok = TRUE )
430430 if (! is.null(normals_years )) {
431-
432- if (normals_years == " 1991-2020" ) {
433- message(
434- " You can find out which stations have normals for 1991-2020, " ,
435- " but be aware that they are not yet available for download via weathercan" )
436- }
437-
438- if (normals_years == " current" ) {
439- yr <- " normals_1981_2010" # Currently set Normals
440- } else {
441- yr <- paste0(" normals_" , stringr :: str_replace(normals_years , " -" , " _" ))
442- }
431+ yr <- paste0(" normals_" , stringr :: str_replace(normals_years , " -" , " _" ))
443432 stn <- dplyr :: filter(stn , .data [[yr ]])
444- } else {
445-
446- if (! is.null(starts_latest )){
447- suppressWarnings({
448- starts_latest <- try(as.numeric(as.character(starts_latest )),
449- silent = TRUE )
450- })
451- if (is.na(starts_latest ) | inherits(starts_latest , " try-error" )){
452- stop(" 'starts_latest' needs to be coercible into numeric" , call. = FALSE )
453- }
454- stn <- dplyr :: filter(stn , .data $ start < = starts_latest )
433+ }
434+
435+ if (! is.null(starts_latest )){
436+ suppressWarnings({
437+ starts_latest <- try(as.numeric(as.character(starts_latest )),
438+ silent = TRUE )
439+ })
440+ if (is.na(starts_latest ) | inherits(starts_latest , " try-error" )){
441+ stop(" 'starts_latest' needs to be a year (YYYY)" , call. = FALSE )
455442 }
456-
457- if ( ! is.null( ends_earliest )){
458- suppressWarnings({
459- ends_earliest <- try(as.numeric(as.character( ends_earliest )),
460- silent = TRUE )
461- })
462- if (is.na( ends_earliest ) | inherits( ends_earliest , " try-error " )){
463- stop( " 'ends_earliest' needs to be coercible into numeric " , call. = FALSE )
464- }
465- stn <- dplyr :: filter( stn , .data $ end > = ends_earliest )
443+ stn <- dplyr :: filter( stn , .data $ start < = starts_latest )
444+ }
445+
446+ if ( ! is.null( ends_earliest )){
447+ suppressWarnings({
448+ ends_earliest <- try(as.numeric(as.character( ends_earliest )),
449+ silent = TRUE )
450+ } )
451+ if (is.na( ends_earliest ) | inherits( ends_earliest , " try-error " )){
452+ stop( " 'ends_earliest' needs to be a year (YYYY) " , call. = FALSE )
466453 }
454+ stn <- dplyr :: filter(stn , .data $ end > = ends_earliest )
467455 }
468456
469457 if (! is.null(name )) {
@@ -519,10 +507,7 @@ stations_search <- function(name = NULL,
519507 .data $ station_name ,
520508 .data $ station_id ,
521509 .data $ interval )
522- if (! is.null(normals_years )) {
523- stn <- dplyr :: select(stn , - " interval" , - " start" , - " end" ) %> %
524- dplyr :: distinct()
525- }
510+
526511 stn
527512}
528513
0 commit comments