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

Incompatability of "bomrang_tbl" class with dplyr functions #105

Closed
Blundys opened this issue Nov 13, 2019 · 4 comments
Closed

Incompatability of "bomrang_tbl" class with dplyr functions #105

Blundys opened this issue Nov 13, 2019 · 4 comments
Assignees
Labels
bug

Comments

@Blundys
Copy link

@Blundys Blundys commented Nov 13, 2019

Hi, your vignette states that the bomrang_tbl class is designed to be compatible with dplyr functions but I have found that it causes many issues. I have included several examples below:

  1. dplyr::group_by() does not preform as expected, subsequent functions such as dplyr::summarise() or dplyr::filter() return results the same as if data was not grouped
  2. If data.frame and bound together using dplyr::bind_rows() even simple functions such as head cause errors (although data can still be accessed)
library(bomrang)
library(dplyr)

Hobart <- get_current_weather("HOBART (ELLERSLIE ROAD)")
Brisbane <- get_current_weather("Brisbane")


# "grouped" data frame only gives 1 results as though ungrouped
Hobart %>% mutate(day = as.Date(local_date_time_full)) %>% group_by(day) %>% summarise(mean(air_temp ))
#>   mean(air_temp)
#> 1       13.74854
# without grouping you get the same results
Hobart %>% mutate(day = as.Date(local_date_time_full)) %>% summarise(mean(air_temp ))
#>   mean(air_temp)
#> 1       13.74854
#to corrected get groups to work we must first convert to data.frame
Hobart %>% as.data.frame() %>% mutate(day = as.Date(local_date_time_full)) %>% group_by(day) %>% summarise(mean(air_temp ))
#> # A tibble: 4 x 2
#>   day        `mean(air_temp)`
#>   <date>                <dbl>
#> 1 2019-11-10             13.5
#> 2 2019-11-11             17.3
#> 3 2019-11-12             10.8
#> 4 2019-11-13             13.5



Combined <- bind_rows(Hobart, Brisbane)
head(Combined)
#> Error in tools::toTitleCase(attr(x, "type")): 'text' must be a character vector
Combineddf <- as.data.frame(Combined)
head(Combineddf)
#>   sort_order   wmo full_name history_product local_date_time
#> 1          0 94970    Hobart        IDT60801      13/01:30pm
#> 2          1 94970    Hobart        IDT60801      13/01:13pm
#> 3          2 94970    Hobart        IDT60801      13/01:00pm
#> 4          3 94970    Hobart        IDT60801      13/12:36pm
#> 5          4 94970    Hobart        IDT60801      13/12:30pm
#> 6          5 94970    Hobart        IDT60801      13/12:11pm
#>   local_date_time_full        aifstime_utc      lat      lon apparent_t
#> 1  2019-11-13 13:30:00 2019-11-13 02:30:00 -42.8897 147.3278        5.9
#> 2  2019-11-13 13:13:00 2019-11-13 02:13:00 -42.8897 147.3278        7.1
#> 3  2019-11-13 13:00:00 2019-11-13 02:00:00 -42.8897 147.3278        9.0
#> 4  2019-11-13 12:36:00 2019-11-13 01:36:00 -42.8897 147.3278        8.6
#> 5  2019-11-13 12:30:00 2019-11-13 01:30:00 -42.8897 147.3278        9.4
#> 6  2019-11-13 12:11:00 2019-11-13 01:11:00 -42.8897 147.3278        5.2
#>   cloud cloud_base_m cloud_oktas cloud_type cloud_type_id delta_t gust_kmh
#> 1     -           NA          NA          -            NA     5.7       74
#> 2     -           NA          NA          -            NA     5.2       74
#> 3     -           NA          NA          -            NA     3.4       50
#> 4     -           NA          NA          -            NA     3.6       61
#> 5     -           NA          NA          -            NA     3.2       43
#> 6     -           NA          NA          -            NA     1.7       76
#>   gust_kt air_temp dewpt press press_msl press_qnh press_tend rain_trace
#> 1      40     15.7   3.2 996.7     996.7     996.8          -        2.8
#> 2      40     15.7   4.7 996.3     996.3     996.4          -        2.8
#> 3      27     14.8   8.1 996.2     996.2     996.3          -        2.6
#> 4      33     14.6   7.2 996.1     996.1     996.2          -        2.4
#> 5      23     14.4   7.9 996.2     996.2     996.3          -        2.4
#> 6      41     11.1   7.6 996.4     996.4     996.5          -        2.2
#>   rel_hum sea_state swell_dir_worded swell_height swell_period vis_km
#> 1      NA         -                -           NA           NA      -
#> 2      NA         -                -           NA           NA      -
#> 3      NA         -                -           NA           NA      -
#> 4      NA         -                -           NA           NA      -
#> 5      NA         -                -           NA           NA      -
#> 6      NA         -                -           NA           NA      -
#>   weather wind_dir wind_spd_kmh wind_spd_kt
#> 1       -      WSW           44          24
#> 2       -        W           39          21
#> 3       -        W           28          15
#> 4       -        W           28          15
#> 5       -        W           24          13
#> 6       -       NW           28          15

Created on 2019-11-13 by the reprex package (v0.3.0)

@jonocarroll jonocarroll self-assigned this Nov 13, 2019
@jonocarroll
Copy link
Collaborator

@jonocarroll jonocarroll commented Nov 13, 2019

Interesting... thanks for the report. I'll have a look into what's going on.

adamhsparks added a commit that referenced this issue Nov 22, 2019
Resolve group_by issues (#105)
@adamhsparks
Copy link
Member

@adamhsparks adamhsparks commented Jan 7, 2020

The group_by() bug is fixed in the 0.6.1 release that I had to make to keep CRAN happy due to some failing tests on the CRAN server.

The bind_rows() bug still exists and should be fixed in the next release.

@adamhsparks adamhsparks added the bug label Jan 7, 2020
@PaulMelloy
Copy link
Contributor

@PaulMelloy PaulMelloy commented Jan 15, 2020

Hello,
This bug is still happening for me.

install.packages("bomrang")
library(dplyr)
library(devtools)
#install_github("https://github.com/ropensci/bomrang")
library(bomrang)

dat1 <- get_historical(stationid = sweep_for_stations()[1,1])

dat1 %>%
   group_by(year) %>%
   summarise(rain.mean = mean(rainfall,na.rm = TRUE))

class(dat1)

data.frame(dat1) %>%
   group_by(year) %>%
   summarise(rain.mean = mean(rainfall,na.rm = TRUE))



dat2 <- get_current_weather(station_name = sweep_for_stations()[1,3])

dat2 %>%
   group_by(cloud) %>%
   summarise(mean_temp = mean(air_temp, na.rm = TRUE))

data.frame(dat2) %>%
   group_by(cloud) %>%
   summarise(mean_temp = mean(air_temp, na.rm = TRUE))
@PaulMelloy
Copy link
Contributor

@PaulMelloy PaulMelloy commented Jan 16, 2020

I updated my version of R and now it is working

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

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.