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

export as.igraph #117

Open
thibautjombart opened this issue Dec 10, 2019 · 2 comments
Open

export as.igraph #117

thibautjombart opened this issue Dec 10, 2019 · 2 comments

Comments

@thibautjombart
Copy link
Contributor

thibautjombart commented Dec 10, 2019

Reported by Bertrand Sudre during his time with the analytics cell of the EOC, DRC:

library(outbreaks)
library(epicontacts)
attach(mers_korea_2015)
str(mers_korea_2015)
#> List of 2
#>  $ linelist:'data.frame':    162 obs. of  15 variables:
#>   ..$ id            : chr [1:162] "SK_1" "SK_2" "SK_3" "SK_4" ...
#>   ..$ age           : int [1:162] 68 63 76 46 50 71 28 46 56 44 ...
#>   ..$ age_class     : chr [1:162] "60-69" "60-69" "70-79" "40-49" ...
#>   ..$ sex           : Factor w/ 2 levels "F","M": 2 1 2 1 2 2 1 1 2 2 ...
#>   ..$ place_infect  : Factor w/ 2 levels "Middle East",..: 1 2 2 2 2 2 2 2 2 2 ...
#>   ..$ reporting_ctry: Factor w/ 2 levels "China","South Korea": 2 2 2 2 2 2 2 2 2 1 ...
#>   ..$ loc_hosp      : Factor w/ 13 levels "365 Yeollin Clinic, Seoul",..: 10 10 10 10 1 10 10 13 10 10 ...
#>   ..$ dt_onset      : Date[1:162], format: "2015-05-11" "2015-05-18" ...
#>   ..$ dt_report     : Date[1:162], format: "2015-05-19" "2015-05-20" ...
#>   ..$ week_report   : Factor w/ 5 levels "2015_21","2015_22",..: 1 1 1 2 2 2 2 2 2 2 ...
#>   ..$ dt_start_exp  : Date[1:162], format: "2015-04-18" "2015-05-15" ...
#>   ..$ dt_end_exp    : Date[1:162], format: "2015-05-04" "2015-05-20" ...
#>   ..$ dt_diag       : Date[1:162], format: "2015-05-20" "2015-05-20" ...
#>   ..$ outcome       : Factor w/ 2 levels "Alive","Dead": 1 1 2 1 1 2 1 1 1 1 ...
#>   ..$ dt_death      : Date[1:162], format: NA NA ...
#>  $ contacts:'data.frame':    98 obs. of  4 variables:
#>   ..$ from         : chr [1:98] "SK_14" "SK_14" "SK_14" "SK_14" ...
#>   ..$ to           : chr [1:98] "SK_113" "SK_116" "SK_41" "SK_112" ...
#>   ..$ exposure     : Factor w/ 5 levels "Contact with HCW",..: 2 2 2 2 2 2 2 2 2 2 ...
#>   ..$ diff_dt_onset: int [1:98] 10 13 14 14 15 15 15 16 16 16 ...

x <- make_epicontacts(linelist = mers_korea_2015$linelist,
                      contacts = mers_korea_2015$contacts,
                      directed = TRUE)
str(x)
#> List of 3
#>  $ linelist:'data.frame':    162 obs. of  15 variables:
#>   ..$ id            : chr [1:162] "SK_1" "SK_2" "SK_3" "SK_4" ...
#>   ..$ age           : int [1:162] 68 63 76 46 50 71 28 46 56 44 ...
#>   ..$ age_class     : chr [1:162] "60-69" "60-69" "70-79" "40-49" ...
#>   ..$ sex           : Factor w/ 2 levels "F","M": 2 1 2 1 2 2 1 1 2 2 ...
#>   ..$ place_infect  : Factor w/ 2 levels "Middle East",..: 1 2 2 2 2 2 2 2 2 2 ...
#>   ..$ reporting_ctry: Factor w/ 2 levels "China","South Korea": 2 2 2 2 2 2 2 2 2 1 ...
#>   ..$ loc_hosp      : Factor w/ 13 levels "365 Yeollin Clinic, Seoul",..: 10 10 10 10 1 10 10 13 10 10 ...
#>   ..$ dt_onset      : Date[1:162], format: "2015-05-11" "2015-05-18" ...
#>   ..$ dt_report     : Date[1:162], format: "2015-05-19" "2015-05-20" ...
#>   ..$ week_report   : Factor w/ 5 levels "2015_21","2015_22",..: 1 1 1 2 2 2 2 2 2 2 ...
#>   ..$ dt_start_exp  : Date[1:162], format: "2015-04-18" "2015-05-15" ...
#>   ..$ dt_end_exp    : Date[1:162], format: "2015-05-04" "2015-05-20" ...
#>   ..$ dt_diag       : Date[1:162], format: "2015-05-20" "2015-05-20" ...
#>   ..$ outcome       : Factor w/ 2 levels "Alive","Dead": 1 1 2 1 1 2 1 1 1 1 ...
#>   ..$ dt_death      : Date[1:162], format: NA NA ...
#>  $ contacts:'data.frame':    98 obs. of  4 variables:
#>   ..$ from         : chr [1:98] "SK_14" "SK_14" "SK_14" "SK_14" ...
#>   ..$ to           : chr [1:98] "SK_113" "SK_116" "SK_41" "SK_112" ...
#>   ..$ exposure     : Factor w/ 5 levels "Contact with HCW",..: 2 2 2 2 2 2 2 2 2 2 ...
#>   ..$ diff_dt_onset: int [1:98] 10 13 14 14 15 15 15 16 16 16 ...
#>  $ directed: logi TRUE
#>  - attr(*, "class")= chr "epicontacts"

## this does not work
test <- as.igraph(x)
#> Error in as.igraph(x): could not find function "as.igraph"
test <- epicontacts::as.igraph.epicontacts(x)
#> Error: 'as.igraph.epicontacts' is not an exported object from 'namespace:epicontacts'

## this works
test <- epicontacts:::as.igraph.epicontacts(x)

Created on 2019-12-10 by the reprex package (v0.3.0)

It would be good to ensure the conversion function is exported and documented.

@zkamvar
Copy link
Member

zkamvar commented Dec 11, 2019

This is a duplicate of #98. This issue exists because of weird S3 caveats: #98 (comment)

@thibautjombart
Copy link
Contributor Author

It did sound familiar, and weirdly enough I managed not to find the other issue. Thanks.

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

No branches or pull requests

2 participants