Skip to content

export as.igraph #117

Description

@thibautjombart

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.

Activity

  1. zkamvar commented on Dec 11, 2019

    @zkamvar
    Member

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

  2. thibautjombart commented on Dec 11, 2019

    @thibautjombart
    ContributorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions