R Under development (unstable) (2024-10-01 r87205 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > ## Copyright 2013-2020 Stefan Widgren and Maria Noremark, > ## National Veterinary Institute, Sweden > ## > ## Licensed under the EUPL, Version 1.1 or - as soon they > ## will be approved by the European Commission - subsequent > ## versions of the EUPL (the "Licence"); > ## You may not use this work except in compliance with the > ## Licence. > ## You may obtain a copy of the Licence at: > ## > ## http://ec.europa.eu/idabc/eupl > ## > ## Unless required by applicable law or agreed to in > ## writing, software distributed under the Licence is > ## distributed on an "AS IS" basis, > ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either > ## express or implied. > ## See the Licence for the specific language governing > ## permissions and limitations under the Licence. > > library(EpiContactTrace) > > ## > ## Node position checking > ## > > ## > ## Case 1 > ## > tree <- data.frame( + node = c("O", "E", "F", "N", "A", "D", "G", "M", + "B", "C", "H", "I", "J", "K", "L"), + parent = c(NA, "O", "O", "O", "E", "E", "N", "N", + "D", "D", "M", "M", "M", "M", "M"), + level = c(0, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3), + stringsAsFactors = FALSE) > > tree_exp <- data.frame( + node = c("O", "E", "F", "N", "A", "D", "G", "M", + "B", "C", "H", "I", "J", "K", "L"), + parent = c(NA, "O", "O", "O", "E", "E", "N", "N", + "D", "D", "M", "M", "M", "M", "M"), + level = c(0, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3), + x = c(0, -10.5, 0, 10.5, -13.5, -7.5, 7.5, 13.5, -10.5, + -4.5, 1.5, 7.5, 13.5, 19.5, 25.5), + y = c(0, -1, -1, -1, -2, -2, -2, -2, -3, -3, -3, -3, -3, + -3, -3), + stringsAsFactors = FALSE) > > tree_obs <- EpiContactTrace:::position_tree(tree) > tree_obs$level <- as.numeric(tree_obs$level) > str(tree_obs) 'data.frame': 15 obs. of 5 variables: $ node : chr "O" "E" "F" "N" ... $ parent: chr NA "O" "O" "O" ... $ level : num 0 1 1 1 2 2 2 2 3 3 ... $ x : num 0 -10.5 0 10.5 -13.5 -7.5 7.5 13.5 -10.5 -4.5 ... $ y : num 0 -1 -1 -1 -2 -2 -2 -2 -3 -3 ... > stopifnot(identical(tree_obs, tree_exp)) > > proc.time() user system elapsed 0.26 0.07 0.32