├── .Rbuildignore ├── .github └── workflows │ ├── R-CMD-check.yaml │ ├── changed_warnings.py │ ├── lint-changed-warnings.yaml │ ├── public-private-sync.yml │ └── rhub.yaml ├── .gitignore ├── COPYING ├── ChangeLog ├── DESCRIPTION ├── NAMESPACE ├── R ├── access.R ├── as.edgelist.R ├── assignment.R ├── coercion.R ├── constructors.R ├── dataframe.R ├── fileio.R ├── layout.R ├── misc.R ├── network-package.R ├── operators.R ├── plot.R ├── printsum.R └── zzz.R ├── README.md ├── codecov.yml ├── data ├── emon.RData └── flo.RData ├── inst ├── CITATION ├── include │ ├── netregistration.h │ └── network.h └── network.api │ ├── networkapi.c │ └── networkapi.h ├── man ├── add.edges.Rd ├── add.vertices.Rd ├── as.color.Rd ├── as.data.frame.network.Rd ├── as.edgelist.Rd ├── as.matrix.network.Rd ├── as.network.matrix.Rd ├── as.sociomatrix.Rd ├── attribute.methods.Rd ├── deletion.methods.Rd ├── edgeset.constructors.Rd ├── emon.Rd ├── flo.Rd ├── get.edges.Rd ├── get.inducedSubgraph.Rd ├── get.neighborhood.Rd ├── has.edges.Rd ├── is.adjacent.Rd ├── loading.attributes.Rd ├── mixingmatrix.Rd ├── network-internal.Rd ├── network-operators.Rd ├── network-package.Rd ├── network.Rd ├── network.arrow.Rd ├── network.density.Rd ├── network.dyadcount.Rd ├── network.edgecount.Rd ├── network.edgelabel.Rd ├── network.extraction.Rd ├── network.indicators.Rd ├── network.initialize.Rd ├── network.layout.Rd ├── network.loop.Rd ├── network.naedgecount.Rd ├── network.size.Rd ├── network.vertex.Rd ├── permute.vertexIDs.Rd ├── plot.network.Rd ├── preparePlotArgs.Rd ├── prod.network.Rd ├── read.paj.Rd ├── sum.network.Rd ├── valid.eids.Rd └── which.matrix.type.Rd ├── src ├── Rinit.c ├── access.c ├── access.h ├── constructors.c ├── constructors.h ├── layout.c ├── layout.h ├── utils.c └── utils.h ├── tests ├── benchmarks ├── general.tests.R ├── general.tests2.R ├── list.attribute.tests.R ├── network.access.test.R ├── network.battery.R ├── pathological.tests.R ├── plotflo.R ├── speedTests.R ├── testthat.R ├── testthat │ ├── test-as.edgelist.R │ ├── test-dataframe.R │ ├── test-i22-summary-character.R │ ├── test-indexing.R │ ├── test-misc_tests.R │ ├── test-mixingmatrix.R │ ├── test-networks.R │ ├── test-plot.R │ └── test-read.paj.R └── vignette.R └── vignettes ├── networkVignette.Rnw └── networkVignette.pdf /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^Meta$ 2 | ^doc$ 3 | ^.*\.Rproj$ 4 | ^\.Rproj\.user$ 5 | .RSession 6 | ^.*/\.RData$ 7 | ^.*/\.Rhistory 8 | ^.*/Rplots.pdf 9 | ^.*/figure/ 10 | .travis.yml 11 | appveyor.yml 12 | .*\.orig$ 13 | .*\.rej$ 14 | .gdb_history 15 | ^revdep$ 16 | ^.github$ 17 | ^man-roxygen$ 18 | ^codecov\.yml$ 19 | ^vignettes/.*_cache$ 20 | ^vignettes/.*_files$ 21 | ^README.md$ 22 | -------------------------------------------------------------------------------- /.github/workflows/changed_warnings.py: -------------------------------------------------------------------------------- 1 | import re 2 | from operator import add 3 | from collections import defaultdict 4 | import sys 5 | 6 | HEAD_RE = re.compile("^(?P[@+ -])(@ *-(?P[0-9]+))?") 7 | 8 | class LineMapper: 9 | def __init__(self, patch): 10 | matches = [HEAD_RE.match(line) for line in patch.split('\n')] 11 | starts = [int(m['s']) for m in matches if m['t'] == '@'] 12 | lines = ''.join([m['t'] for m in matches[1:]]).split('@') 13 | lens = [len(l) for l in lines] 14 | ends = list(map(add, starts, lens)) 15 | 16 | self.lmap = [0] * max(ends) 17 | 18 | pos1 = 0 19 | pos2 = 0 20 | 21 | for ch in range(len(starts)): 22 | gap = starts[ch] - pos1 - 1 23 | self.lmap[pos1:(pos1 + gap)] = range(pos2 + 1, pos2 + gap + 1) 24 | 25 | pos1 = pos1 + gap 26 | pos2 = pos2 + gap 27 | 28 | for d in lines[ch]: 29 | if d in [' ', '-']: pos1 += 1 30 | if d in [' ', '+']: pos2 += 1 31 | if d == ' ': self.lmap[pos1 - 1] = pos2 32 | 33 | gap = len(self.lmap) - pos1 34 | self.lmap[pos1:(pos1 + gap)] = range(pos2 + 1, pos2 + gap + 1) 35 | 36 | self.shift = pos2 - pos1 37 | 38 | def __getitem__(self, key): 39 | if key == 0: return 0 40 | elif key <= len(self.lmap): return self.lmap[key - 1] 41 | else: return key + self.shift 42 | 43 | def chunk(l, each): 44 | for i in range(0, len(l), each): 45 | yield l[i:i+each] 46 | 47 | def split_lines(lines, prefix, each = 10): # 10 = GitHub max per step. 48 | for i, l in enumerate(chunk(lines, each)): 49 | open(prefix + str(i + 1) + '.txt', 'w').writelines(l) 50 | 51 | def split_by_file(lines, file_regex): 52 | o = defaultdict(list) 53 | for l in lines: 54 | f = file_regex.match(l)['file'] 55 | o[f].append(l) 56 | 57 | return dict(o) 58 | 59 | def split_patch_by_file(patch): 60 | patch = patch.split('\n') 61 | o = {} 62 | f = None 63 | 64 | for l in patch: 65 | if l.startswith('diff'): 66 | parts = l.strip().split() 67 | # The file name is usually after 'b/' (the new file) 68 | for part in parts: 69 | if part.startswith('b/'): 70 | f = part[2:] 71 | else: 72 | o[f] += l + '\n' 73 | 74 | return dict(o) 75 | 76 | def uniq_messages(old, new): 77 | return [msg for msg in new if msg not in set(old)] 78 | 79 | def remap_file_messages(old, patch, line_regex, line_replace): 80 | m = LineMapper(patch) 81 | ol = [int(line_regex.match(l)['line']) for l in old] 82 | nl = [m[l] for l in ol] 83 | 84 | return list(map(line_replace, old, ol, nl)) 85 | 86 | def filter_messages(old, new, patch_dict, message_regex, line_replace): 87 | old = split_by_file(old, message_regex) 88 | new = split_by_file(new, message_regex) 89 | 90 | o = [] 91 | for f in new.keys() & patch_dict.keys(): 92 | oldnew = remap_file_messages(old.get(f, []), patch_dict[f], message_regex, line_replace) 93 | o.extend(uniq_messages(oldnew, new[f])) 94 | 95 | return o 96 | 97 | -------------------------------------------------------------------------------- /.github/workflows/public-private-sync.yml: -------------------------------------------------------------------------------- 1 | ### WARNING: This action script uses force pushing and so it can potentially overwrite repositories. 2 | 3 | ## Usage: 4 | # 5 | # 1. Copy this file to the .github/workflows/ directory at the root of the main branch of your public repository. Do NOT push it yet. 6 | # 2. IF your repositories DON'T follow the standard naming convention (public: USER/PKG, private: USER/PKG-private), THEN set the repository names in the env statement below. (OTHERWISE, leave them blank.) 7 | # 3. IF your package is hosted OUTSIDE the Statnet organization, THEN from the repository statnet/janitors-closet, obtain file ssh_keys/statnet-janitor.id_rsa . 8 | # 4. For each of the two repositories, 9 | # 4.1. IF your package is hosted IN the Statnet organization, THEN go to Settings -> Secrets, click "Manage organization secrets", click "Update" next to "JANITORS_SSH_KEY", click on the gear icon, and tick your repository's box if it isn't already ticked. OTHERWISE, go to Settings -> Secrets, click "New Secret", enter Name "JANITORS_SSH_KEY", and paste the contents of ssh_keysstatnet-janitor.id_rsa into Value. 10 | # 4.2. Go to Settings -> Manage Access, click "Invite Teams or People" (or "Invite People"), and invite statnet-janitor as a collaborator with read and write access. 11 | # 4.3. IF your package is hosted OUTSIDE the Statnet organization, THEN log in as statnet-janitor and accept the invitation. 12 | # 5. Push this file to the repository. (It should propagate automatically.) 13 | 14 | # Set public and private repositories (i.e., USER/PKG). Leave blank to autodetect. 15 | env: 16 | PUBLIC: '' 17 | PRIVATE: '' 18 | 19 | on: push 20 | jobs: 21 | public-private-sync: 22 | runs-on: ubuntu-latest 23 | env: 24 | KEY_AVAILABLE: ${{ secrets.JANITORS_SSH_KEY != '' }} 25 | steps: 26 | - name: check-config # Make sure either neither or both are set; abort if not. 27 | if: (env.PUBLIC == '') != (env.PRIVATE == '') 28 | run: | 29 | echo "Configuration problem: only one of the repositories is set." 30 | exit 1 31 | - name: detect-repos 32 | if: env.KEY_AVAILABLE != 'false' && env.PUBLIC == '' && env.PRIVATE == '' # If Janitor's key is not present, then we are probably in a fork, so don't autodetect (which then effectively disables all subsequent steps if PUBLIC and PRIVATE aren't set). 33 | run: | 34 | if [[ "${{ github.repository }}" == *-private ]] 35 | then # Current repo is private. 36 | PRIVATE="${{ github.repository }}" 37 | PUBLIC="${PRIVATE%-private}" 38 | else # Current repo is public. 39 | PUBLIC="${{ github.repository }}" 40 | PRIVATE="$PUBLIC-private" 41 | fi 42 | echo "PRIVATE=$PRIVATE" >> $GITHUB_ENV 43 | echo "PUBLIC=$PUBLIC" >> $GITHUB_ENV 44 | - name: repo-sync-public-private # From public repo, sync whatever branch was pushed. 45 | if: github.repository == env.PUBLIC 46 | uses: wei/git-sync@v2 47 | with: 48 | source_repo: ${{ env.PUBLIC }} 49 | source_branch: ${{ github.ref }} 50 | destination_repo: ${{ env.PRIVATE }} 51 | destination_branch: ${{ github.ref }} 52 | ssh_private_key: ${{ secrets.JANITORS_SSH_KEY }} 53 | - name: public-check # Check if the branch/tag exists in the public repository. 54 | if: github.repository == env.PRIVATE # Only check if from private repo. 55 | run: | 56 | set +e 57 | git ls-remote --exit-code https://github.com/${{ env.PUBLIC }} ${{ github.ref }} 58 | echo "FOUND_PUBLIC=$?" >> $GITHUB_ENV 59 | - name: repo-sync-private-public # From private repo, sync only if public branch/tag present. 60 | if: github.repository == env.PRIVATE && env.FOUND_PUBLIC == '0' 61 | uses: wei/git-sync@v2 62 | with: 63 | source_repo: ${{ env.PRIVATE }} 64 | source_branch: ${{ github.ref }} 65 | destination_repo: ${{ env.PUBLIC }} 66 | destination_branch: ${{ github.ref }} 67 | ssh_private_key: ${{ secrets.JANITORS_SSH_KEY }} 68 | -------------------------------------------------------------------------------- /.github/workflows/rhub.yaml: -------------------------------------------------------------------------------- 1 | # R-hub's generic GitHub Actions workflow file. It's canonical location is at 2 | # https://github.com/r-hub/actions/blob/v1/workflows/rhub.yaml 3 | # You can update this file to a newer version using the rhub2 package: 4 | # 5 | # rhub::rhub_setup() 6 | # 7 | # It is unlikely that you need to modify this file manually. 8 | 9 | name: R-hub 10 | run-name: "${{ github.event.inputs.id }}: ${{ github.event.inputs.name || format('Manually run by {0}', github.triggering_actor) }}" 11 | 12 | on: 13 | workflow_dispatch: 14 | inputs: 15 | config: 16 | description: 'A comma separated list of R-hub platforms to use.' 17 | type: string 18 | default: 'linux,windows,macos' 19 | name: 20 | description: 'Run name. You can leave this empty now.' 21 | type: string 22 | id: 23 | description: 'Unique ID. You can leave this empty now.' 24 | type: string 25 | 26 | jobs: 27 | 28 | setup: 29 | runs-on: ubuntu-latest 30 | outputs: 31 | containers: ${{ steps.rhub-setup.outputs.containers }} 32 | platforms: ${{ steps.rhub-setup.outputs.platforms }} 33 | 34 | steps: 35 | # NO NEED TO CHECKOUT HERE 36 | - uses: r-hub/actions/setup@v1 37 | with: 38 | config: ${{ github.event.inputs.config }} 39 | id: rhub-setup 40 | 41 | linux-containers: 42 | needs: setup 43 | if: ${{ needs.setup.outputs.containers != '[]' }} 44 | runs-on: ubuntu-latest 45 | name: ${{ matrix.config.label }} 46 | strategy: 47 | fail-fast: false 48 | matrix: 49 | config: ${{ fromJson(needs.setup.outputs.containers) }} 50 | container: 51 | image: ${{ matrix.config.container }} 52 | 53 | steps: 54 | - uses: r-hub/actions/checkout@v1 55 | - uses: r-hub/actions/platform-info@v1 56 | with: 57 | token: ${{ secrets.RHUB_TOKEN }} 58 | job-config: ${{ matrix.config.job-config }} 59 | - uses: r-hub/actions/setup-deps@v1 60 | with: 61 | token: ${{ secrets.RHUB_TOKEN }} 62 | job-config: ${{ matrix.config.job-config }} 63 | - uses: r-hub/actions/run-check@v1 64 | with: 65 | token: ${{ secrets.RHUB_TOKEN }} 66 | job-config: ${{ matrix.config.job-config }} 67 | 68 | other-platforms: 69 | needs: setup 70 | if: ${{ needs.setup.outputs.platforms != '[]' }} 71 | runs-on: ${{ matrix.config.os }} 72 | name: ${{ matrix.config.label }} 73 | strategy: 74 | fail-fast: false 75 | matrix: 76 | config: ${{ fromJson(needs.setup.outputs.platforms) }} 77 | 78 | steps: 79 | - uses: r-hub/actions/checkout@v1 80 | - uses: r-hub/actions/setup-r@v1 81 | with: 82 | job-config: ${{ matrix.config.job-config }} 83 | token: ${{ secrets.RHUB_TOKEN }} 84 | - uses: r-hub/actions/platform-info@v1 85 | with: 86 | token: ${{ secrets.RHUB_TOKEN }} 87 | job-config: ${{ matrix.config.job-config }} 88 | - uses: r-hub/actions/setup-deps@v1 89 | with: 90 | job-config: ${{ matrix.config.job-config }} 91 | token: ${{ secrets.RHUB_TOKEN }} 92 | - uses: r-hub/actions/run-check@v1 93 | with: 94 | job-config: ${{ matrix.config.job-config }} 95 | token: ${{ secrets.RHUB_TOKEN }} 96 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # History files 2 | .Rhistory 3 | .Rapp.history 4 | 5 | # Session Data files 6 | .RData 7 | .RSession 8 | 9 | # Example code in package build process 10 | *-Ex.R 11 | 12 | # Output files from R CMD build 13 | /*.tar.gz 14 | 15 | # Output files from R CMD check 16 | /*.Rcheck/ 17 | 18 | # RStudio files 19 | .Rproj.user/ 20 | *.Rproj 21 | 22 | 23 | # produced vignettes 24 | vignettes/*.html 25 | vignettes/*.pdf 26 | 27 | # OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3 28 | .httr-oauth 29 | 30 | # knitr and R markdown default cache directories 31 | /*_cache/ 32 | /cache/ 33 | 34 | # Temporary files created by R markdown 35 | *.utf8.md 36 | *.knit.md 37 | # Prerequisites 38 | *.d 39 | 40 | # Object files 41 | *.o 42 | *.ko 43 | *.obj 44 | *.elf 45 | 46 | # Linker output 47 | *.ilk 48 | *.map 49 | *.exp 50 | 51 | # Precompiled Headers 52 | *.gch 53 | *.pch 54 | 55 | # Libraries 56 | *.lib 57 | *.a 58 | *.la 59 | *.lo 60 | 61 | # Shared objects (inc. Windows DLLs) 62 | *.dll 63 | *.so 64 | *.so.* 65 | *.dylib 66 | 67 | # Executables 68 | *.exe 69 | *.out 70 | *.app 71 | *.i*86 72 | *.x86_64 73 | *.hex 74 | 75 | # Debug files 76 | *.dSYM/ 77 | *.su 78 | *.idb 79 | *.pdb 80 | 81 | # Kernel Module Compile Results 82 | *.mod* 83 | *.cmd 84 | modules.order 85 | Module.symvers 86 | Mkfile.old 87 | dkms.conf 88 | 89 | # Backup files 90 | *~ 91 | *.bak 92 | .Rproj.user 93 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | network Package for R - Classes for Relational Data 2 | 3 | Copyright (C) 2005-2021 Carter T. Butts, Mark S. Handcock, David R. Hunter, 4 | Martina Morris, and others (see DESCRIPTION). 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | 20 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: network 2 | Version: 1.19.0 3 | Date: 2024-12-08 4 | Title: Classes for Relational Data 5 | Authors@R: c( 6 | person("Carter T.", "Butts", role=c("aut","cre"), email="buttsc@uci.edu"), 7 | person("David", "Hunter", role=c("ctb"), email="dhunter@stat.psu.edu"), 8 | person("Mark", "Handcock", role=c("ctb"), email="handcock@stat.ucla.edu"), 9 | person("Skye", "Bender-deMoll", role=c("ctb"), email="skyebend@uw.edu"), 10 | person("Jeffrey", "Horner", role=c("ctb"), email="jeffrey.horner@gmail.com"), 11 | person("Li", "Wang", role=c("ctb"), email="lxwang@uw.edu"), 12 | person("Pavel N.", "Krivitsky", role=c("ctb"), email="pavel@statnet.org", comment=c(ORCID="0000-0002-9101-3362")), 13 | person("Brendan", "Knapp", role=c("ctb"), email="brendan.g.knapp@gmail.com", comment=c(ORCID="0000-0003-3284-4972")), 14 | person("Michał", "Bojanowski", role=c("ctb"), email = "michal2992@gmail.com", comment = c(ORCID = "0000-0001-7503-852X")), 15 | person("Chad", "Klumb", role=c("ctb"), email="cklumb@gmail.com")) 16 | Maintainer: Carter T. Butts 17 | Depends: R (>= 2.10), utils 18 | Imports: tibble, magrittr, statnet.common (>= 4.5), stats 19 | Suggests: 20 | sna, 21 | testthat, 22 | covr 23 | Description: Tools to create and modify network objects. The network class can represent a range of relational data types, and supports arbitrary vertex/edge/graph attributes. 24 | License: GPL (>=2) 25 | URL: https://statnet.org/ 26 | RoxygenNote: 7.3.2.9000 27 | Roxygen: list(markdown = TRUE) 28 | Collate: 29 | 'access.R' 30 | 'as.edgelist.R' 31 | 'assignment.R' 32 | 'coercion.R' 33 | 'constructors.R' 34 | 'dataframe.R' 35 | 'fileio.R' 36 | 'layout.R' 37 | 'misc.R' 38 | 'network-package.R' 39 | 'operators.R' 40 | 'plot.R' 41 | 'printsum.R' 42 | 'zzz.R' 43 | Encoding: UTF-8 44 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method("!",network) 4 | S3method("$",mixingmatrix) 5 | S3method("%c%",network) 6 | S3method("&",network) 7 | S3method("*",network) 8 | S3method("+",network) 9 | S3method("-",network) 10 | S3method("[",network) 11 | S3method("[<-",network) 12 | S3method("[[",mixingmatrix) 13 | S3method("|",network) 14 | S3method(add.edge,network) 15 | S3method(add.edges,network) 16 | S3method(add.vertices,network) 17 | S3method(as.data.frame,network) 18 | S3method(as.edgelist,matrix) 19 | S3method(as.edgelist,network) 20 | S3method(as.edgelist,tbl_df) 21 | S3method(as.matrix,network) 22 | S3method(as.matrix.network,adjacency) 23 | S3method(as.matrix.network,edgelist) 24 | S3method(as.matrix.network,incidence) 25 | S3method(as.network,data.frame) 26 | S3method(as.network,default) 27 | S3method(as.network,matrix) 28 | S3method(as.network,network) 29 | S3method(as.tibble,network) 30 | S3method(as_tibble,network) 31 | S3method(delete.edge.attribute,network) 32 | S3method(delete.edges,network) 33 | S3method(delete.network.attribute,network) 34 | S3method(delete.vertex.attribute,network) 35 | S3method(delete.vertices,network) 36 | S3method(get.edge.attribute,list) 37 | S3method(get.edge.attribute,network) 38 | S3method(get.edge.value,list) 39 | S3method(get.edge.value,network) 40 | S3method(get.inducedSubgraph,network) 41 | S3method(get.network.attribute,network) 42 | S3method(get.vertex.attribute,network) 43 | S3method(is.bipartite,mixingmatrix) 44 | S3method(is.bipartite,network) 45 | S3method(is.directed,mixingmatrix) 46 | S3method(is.directed,network) 47 | S3method(is.na,network) 48 | S3method(list.edge.attributes,network) 49 | S3method(list.network.attributes,network) 50 | S3method(list.vertex.attributes,network) 51 | S3method(mixingmatrix,network) 52 | S3method(network.dyadcount,network) 53 | S3method(network.edgecount,network) 54 | S3method(network.naedgecount,network) 55 | S3method(network.size,network) 56 | S3method(permute.vertexIDs,network) 57 | S3method(plot,network) 58 | S3method(plot.network,default) 59 | S3method(print,mixingmatrix) 60 | S3method(print,network) 61 | S3method(print,summary.network) 62 | S3method(prod,network) 63 | S3method(set.edge.attribute,network) 64 | S3method(set.edge.value,network) 65 | S3method(set.network.attribute,network) 66 | S3method(set.vertex.attribute,network) 67 | S3method(sum,network) 68 | S3method(summary,network) 69 | S3method(valid.eids,network) 70 | export("!.network") 71 | export("%c%") 72 | export("%c%.network") 73 | export("%e%") 74 | export("%e%<-") 75 | export("%eattr%") 76 | export("%eattr%<-") 77 | export("%n%") 78 | export("%n%<-") 79 | export("%nattr%") 80 | export("%nattr%<-") 81 | export("%s%") 82 | export("%v%") 83 | export("%v%<-") 84 | export("%vattr%") 85 | export("%vattr%<-") 86 | export("&.network") 87 | export("*.network") 88 | export("+.network") 89 | export("-.network") 90 | export("<-.network") 91 | export("[.network") 92 | export("[<-.network") 93 | export("network.vertex.names<-") 94 | export("|.network") 95 | export(add.edge) 96 | export(add.edge.network) 97 | export(add.edges) 98 | export(add.edges.network) 99 | export(add.vertices) 100 | export(add.vertices.network) 101 | export(as.color) 102 | export(as.data.frame.network) 103 | export(as.edgelist) 104 | export(as.edgelist.matrix) 105 | export(as.matrix.network) 106 | export(as.matrix.network.adjacency) 107 | export(as.matrix.network.edgelist) 108 | export(as.matrix.network.incidence) 109 | export(as.network) 110 | export(as.network.data.frame) 111 | export(as.network.default) 112 | export(as.network.matrix) 113 | export(as.network.network) 114 | export(as.sociomatrix) 115 | export(delete.edge.attribute) 116 | export(delete.edges) 117 | export(delete.network.attribute) 118 | export(delete.vertex.attribute) 119 | export(delete.vertices) 120 | export(get.dyads.eids) 121 | export(get.edge.attribute) 122 | export(get.edge.value) 123 | export(get.edgeIDs) 124 | export(get.edges) 125 | export(get.inducedSubgraph) 126 | export(get.neighborhood) 127 | export(get.network.attribute) 128 | export(get.vertex.attribute) 129 | export(has.edges) 130 | export(has.loops) 131 | export(is.adjacent) 132 | export(is.bipartite) 133 | export(is.color) 134 | export(is.directed) 135 | export(is.discrete) 136 | export(is.discrete.character) 137 | export(is.discrete.numeric) 138 | export(is.edgelist) 139 | export(is.hyper) 140 | export(is.multiplex) 141 | export(is.na.network) 142 | export(is.network) 143 | export(list.edge.attributes) 144 | export(list.network.attributes) 145 | export(list.vertex.attributes) 146 | export(mixingmatrix) 147 | export(network) 148 | export(network.adjacency) 149 | export(network.arrow) 150 | export(network.bipartite) 151 | export(network.copy) 152 | export(network.density) 153 | export(network.dyadcount) 154 | export(network.edgecount) 155 | export(network.edgelabel) 156 | export(network.edgelist) 157 | export(network.incidence) 158 | export(network.initialize) 159 | export(network.layout.circle) 160 | export(network.layout.fruchtermanreingold) 161 | export(network.layout.kamadakawai) 162 | export(network.loop) 163 | export(network.naedgecount) 164 | export(network.size) 165 | export(network.vertex) 166 | export(network.vertex.names) 167 | export(permute.vertexIDs) 168 | export(plot.network) 169 | export(plot.network.default) 170 | export(plotArgs.network) 171 | export(print.network) 172 | export(print.summary.network) 173 | export(prod.network) 174 | export(read.paj) 175 | export(set.edge.attribute) 176 | export(set.edge.value) 177 | export(set.network.attribute) 178 | export(set.vertex.attribute) 179 | export(sum.network) 180 | export(summary.network) 181 | export(valid.eids) 182 | export(which.matrix.type) 183 | import(utils) 184 | importFrom(grDevices,colors) 185 | importFrom(grDevices,gray) 186 | importFrom(graphics,locator) 187 | importFrom(graphics,par) 188 | importFrom(graphics,plot) 189 | importFrom(graphics,polygon) 190 | importFrom(graphics,rect) 191 | importFrom(graphics,strheight) 192 | importFrom(graphics,strwidth) 193 | importFrom(graphics,text) 194 | importFrom(magrittr,"%>%") 195 | importFrom(magrittr,set_names) 196 | importFrom(statnet.common,NVL) 197 | importFrom(statnet.common,once) 198 | importFrom(statnet.common,statnetStartupMessage) 199 | importFrom(stats,na.omit) 200 | importFrom(stats,rnorm) 201 | importFrom(tibble,as.tibble) 202 | importFrom(tibble,as_tibble) 203 | importFrom(tibble,tibble) 204 | useDynLib(network, .registration = TRUE) 205 | -------------------------------------------------------------------------------- /R/assignment.R: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # 3 | # assignment.R 4 | # 5 | # Written by Carter T. Butts ; portions contributed by 6 | # David Hunter and Mark S. Handcock 7 | # . 8 | # 9 | # Last Modified 11/26/19 10 | # Licensed under the GNU General Public License version 2 (June, 1991) 11 | # or greater 12 | # 13 | # Part of the R/network package 14 | # 15 | # This file contains various routines for the assignment of network objects 16 | # into calling environments. These are internal functions and not to be used 17 | # by the package users. 18 | # 19 | # Contents: 20 | # 21 | # .findNameInSubsetExpr 22 | # .validLHS 23 | # 24 | ###################################################################### 25 | 26 | 27 | # Recursively traverse the parse tree of the expression x, ensuring that it is 28 | # a valid subset expresssion, and return the name associated with the expression. 29 | # 30 | .findNameInSubsetExpr <- function(x){ 31 | if (inherits(x,'call')){ 32 | # Ensure call is a subset function, one of $, [, or [[ 33 | if(!(deparse(x[[1]]) %in% c('$','[','[['))) return(NA) 34 | 35 | # Make sure arguments are clean 36 | xns <- lapply(x[2:length(x)],.findNameInSubsetExpr) 37 | if (any(is.na(xns))) return(NA) 38 | 39 | # Possible name found 40 | return(xns[[1]]) 41 | } 42 | else if (inherits(x,'name')) 43 | return(deparse(x)) 44 | 45 | NULL 46 | } 47 | 48 | # Return TRUE if x is a valid left-hand-side object that can take a value 49 | 50 | .validLHS <- function(x,ev){ 51 | xn <- .findNameInSubsetExpr(x) 52 | # There are valid expressions for which we don't want to assign into the caller's env. 53 | # For instance, when a user executes z<-add.edges(x+y), then the user obviously 54 | # doesn't want x+y to be assigned. Rather he's using them as temporaries to obtain 55 | # z. OTOH we don't want someone doing something obtuse like add.edges(x[sample(...)]) 56 | # In the first case, it's not wrong to end up here, but in the second case we would 57 | # like to warn the user. But we're not going to at this point. 58 | #warning('Cannot make assignment into ',deparse(x)) 59 | if (!is.null(xn) && !is.na(xn) && exists(xn,envir=ev)) 60 | return(TRUE) 61 | else 62 | return(FALSE) 63 | } 64 | -------------------------------------------------------------------------------- /R/zzz.R: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # 3 | # zzz.R 4 | # 5 | # Written by Carter T. Butts . 6 | # 7 | # Last Modified 11/30/19 8 | # Licensed under the GNU General Public License version 2 (June, 1991) 9 | # or greater 10 | # 11 | # Part of the R/network package 12 | # 13 | ###################################################################### 14 | 15 | .onAttach <- function(libname, pkgname){ 16 | #' @importFrom statnet.common statnetStartupMessage 17 | sm <- statnetStartupMessage("network", c("statnet","ergm","ergm.count","tergm"), TRUE) 18 | if(!is.null(sm)) packageStartupMessage(sm) 19 | } 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # `network`: Classes for Relational Data 2 | 3 | [![rstudio mirror downloads](https://cranlogs.r-pkg.org/badges/network?color=2ED968)](https://cranlogs.r-pkg.org/) 4 | [![cran version](https://www.r-pkg.org/badges/version/network)](https://cran.r-project.org/package=network) 5 | [![Coverage status](https://codecov.io/gh/statnet/network/branch/master/graph/badge.svg)](https://codecov.io/github/statnet/network?branch=master) 6 | [![R build status](https://github.com/statnet/network/workflows/R-CMD-check/badge.svg)](https://github.com/statnet/network/actions) 7 | 8 | Tools to create and modify network objects. The network class can represent a range of relational data types, and supports arbitrary vertex/edge/graph attributes. 9 | 10 | ## Public and Private repositories 11 | 12 | To facilitate open development of the package while giving the core developers an opportunity to publish on their developments before opening them up for general use, this project comprises two repositories: 13 | * A public repository `statnet/network` 14 | * A private repository `statnet/network-private` 15 | 16 | The intention is that all developments in `statnet/network-private` will eventually make their way into `statnet/network` and onto CRAN. 17 | 18 | Developers and Contributing Users to the Statnet Project should read https://statnet.github.io/private/ for information about the relationship between the public and the private repository and the workflows involved. 19 | 20 | ## Latest Windows and MacOS binaries 21 | 22 | A set of binaries is built after every commit to the repository. We strongly encourage testing against them before filing a bug report, as they may contain fixes that have not yet been sent to CRAN. They can be downloaded through the following links: 23 | 24 | * [MacOS binary (a `.tgz` file in a `.zip` file)](https://nightly.link/statnet/network/workflows/R-CMD-check.yaml/master/macOS-rrelease-binaries.zip) 25 | * [Windows binary (a `.zip` file in a `.zip` file)](https://nightly.link/statnet/network/workflows/R-CMD-check.yaml/master/Windows-rrelease-binaries.zip) 26 | 27 | You will need to extract the MacOS `.tgz` or the Windows `.zip` file from the outer `.zip` file before installing. These binaries are usually built under the latest version of R and their operating system and may not work under other versions. 28 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | 3 | coverage: 4 | status: 5 | project: 6 | default: 7 | target: auto 8 | threshold: 1% 9 | informational: true 10 | patch: 11 | default: 12 | target: auto 13 | threshold: 1% 14 | informational: true 15 | -------------------------------------------------------------------------------- /data/emon.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/statnet/network/ffe733f403b625d7eb31ba2e3a0082fa958d7a6b/data/emon.RData -------------------------------------------------------------------------------- /data/flo.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/statnet/network/ffe733f403b625d7eb31ba2e3a0082fa958d7a6b/data/flo.RData -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | # use the generic statnet header text 2 | #' statnet: statnet.cite.head('network') 3 | # ---- BEGIN AUTOGENERATED STATNET CITATION ---- 4 | citHeader(paste0(sQuote("network"), " is part of the Statnet suite of packages. ", 5 | "If you are using the ", sQuote("network"), " package for research that will be published, ", 6 | "we request that you acknowledge this by citing the following.\n", 7 | "For BibTeX format, use toBibtex(citation(\"", "network", 8 | "\")).")) 9 | # ---- END AUTOGENERATED STATNET CITATION ---- 10 | 11 | # generate the standard statnet-style package software manual citation 12 | #' statnet: statnet.cite.pkg('network') 13 | # ---- BEGIN AUTOGENERATED STATNET CITATION ---- 14 | bibentry("Manual", author = structure(list(list(given = "Carter T.", 15 | family = "Butts", role = c("aut", "cre"), email = "buttsc@uci.edu", 16 | comment = NULL)), class = "person"), title = paste("network", 17 | ": ", "Classes for Relational Data", sep = ""), organization = paste("The Statnet Project (\\url{", 18 | "http://www.statnet.org", "})", sep = ""), year = substr("2015-08-31", 19 | 1, 4), note = paste("R package version ", "1.13.0.1", sep = ""), 20 | url = paste("https://CRAN.R-project.org/package=", "network", 21 | sep = "")) 22 | # ---- END AUTOGENERATED STATNET CITATION ---- 23 | 24 | # generate an additional citation for Carter's original paper 25 | bibentry("Article", 26 | title = "network: a Package for Managing Relational Data in R.", 27 | author = person("Carter T.", "Butts", email = "buttsc@uci.edu"), 28 | journal = "Journal of Statistical Software", 29 | year = 2008, 30 | volume = 24, 31 | number = 2, 32 | doi ="10.18637/jss.v024.i02") 33 | 34 | # add a network-specific footer 35 | citFooter("Some additional information regarding the C-level network API can be found in the README file within the network.api subdirectory under the package \"inst\" directory -- check your installed library tree.") 36 | 37 | # add the general statnet footer 38 | #' statnet: statnet.cite.foot('network') 39 | # ---- BEGIN AUTOGENERATED STATNET CITATION ---- 40 | citFooter(paste0("We have invested a lot of time and effort in creating the ", 41 | "Statnet suite of packages for use by other researchers. ", 42 | "Please cite it in all papers where it is used. The package ", 43 | sQuote("network"), " is distributed under the terms of the license ", 44 | "GPL (>= 2)", ".")) 45 | # ---- END AUTOGENERATED STATNET CITATION ---- 46 | -------------------------------------------------------------------------------- /inst/include/netregistration.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "network.h" 5 | 6 | #ifndef NETREGISTRATION_H 7 | #define NETREGISTRATION_H 8 | 9 | void netRegisterFunctions(void){ 10 | 11 | getListElement = (SEXP (*)(SEXP list, const char *str)) 12 | R_GetCCallable("network","getListElement"); 13 | setListElement = (SEXP (*)(SEXP list, const char *str, SEXP elem)) 14 | R_GetCCallable("network","setListElement"); 15 | 16 | /*Register access routines*/ 17 | netGetEdgeAttrib_ptr = (SEXP (*)(SEXP, int, const char*)) R_GetCCallable("network", "getEdgeAttribute"); 18 | netGetEdgeIDs_ptr = (SEXP (*)(SEXP, int, int, const char*, int)) R_GetCCallable("network", "getEdgeIDs"); 19 | netGetEdges_ptr = (SEXP (*)(SEXP, int, int, const char*, int)) R_GetCCallable("network", "getEdges"); 20 | netGetNeighborhood_ptr = (SEXP (*)(SEXP, int, const char*, int)) R_GetCCallable("network", "getNeighborhood"); 21 | netGetNetAttrib_ptr = (SEXP (*)(SEXP, const char*)) R_GetCCallable("network", "getNetworkAttribute"); 22 | netHasLoops_ptr = (int (*)(SEXP)) R_GetCCallable("network", "hasLoops"); 23 | netIsAdj_ptr = (int (*)(SEXP, int, int, int)) R_GetCCallable("network", "isAdjacent"); 24 | netIsDir_ptr = (int (*)(SEXP)) R_GetCCallable("network", "isDirected"); 25 | netIsHyper_ptr = (int (*)(SEXP)) R_GetCCallable("network", "isHyper"); 26 | netIsLoop_ptr = (int (*)(SEXP, SEXP)) R_GetCCallable("network", "isLoop"); 27 | netIsMulti_ptr = (int (*)(SEXP)) R_GetCCallable("network", "isMultiplex"); 28 | netIsNetwork_ptr = (int (*)(SEXP)) R_GetCCallable("network", "isNetwork"); 29 | netNetEdgecount_ptr = (int (*)(SEXP, int)) R_GetCCallable("network", "networkEdgecount"); 30 | netNetSize_ptr = (int (*)(SEXP)) R_GetCCallable("network", "networkSize"); 31 | 32 | /*Register modification routines*/ 33 | netAddEdge_ptr = (SEXP (*)(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP)) R_GetCCallable("network", "addEdge_R"); 34 | netAddEdges_ptr = (SEXP (*)(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP)) R_GetCCallable("network", "addEdges_R"); 35 | netDelEdgeAttrib_ptr = (SEXP (*)(SEXP, int, const char*)) R_GetCCallable("network", "deleteEdgeAttribute"); 36 | netDelVertexAttrib_ptr = (SEXP (*)(SEXP, int, const char*)) R_GetCCallable("network", "deleteVertexAttribute"); 37 | netDelNetAttrib_ptr = (SEXP (*)(SEXP, const char*)) R_GetCCallable("network", "deleteNetworkAttribute"); 38 | netSetNetAttrib_ptr = (SEXP (*)(SEXP, const char*, SEXP)) R_GetCCallable("network", "setNetworkAttribute"); 39 | netSetVertexAttrib_ptr = (SEXP (*)(SEXP, const char*, SEXP, int)) R_GetCCallable("network", "setVertexAttribute"); 40 | 41 | } 42 | #endif 43 | -------------------------------------------------------------------------------- /inst/include/network.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #ifndef NETWORK_H 5 | #define NETWORK_H 6 | 7 | SEXP (*getListElement)(SEXP list, const char *str); 8 | SEXP (*setListElement)(SEXP list, const char *str, SEXP elem); 9 | 10 | /* Legacy networkapi.h functions */ 11 | /* Access functions*/ 12 | SEXP (*netGetEdgeAttrib_ptr)(SEXP, int, const char*); 13 | SEXP (*netGetEdgeIDs_ptr)(SEXP, int, int, const char*, int); 14 | SEXP (*netGetEdges_ptr)(SEXP, int, int, const char*, int); 15 | SEXP (*netGetNeighborhood_ptr)(SEXP, int, const char*, int); 16 | SEXP (*netGetNetAttrib_ptr)(SEXP, const char*); 17 | int (*netHasLoops_ptr)(SEXP); 18 | int (*netIsAdj_ptr)(SEXP, int, int, int); 19 | int (*netIsDir_ptr)(SEXP); 20 | int (*netIsHyper_ptr)(SEXP); 21 | int (*netIsLoop_ptr)(SEXP, SEXP); 22 | int (*netIsMulti_ptr)(SEXP); 23 | int (*netIsNetwork_ptr)(SEXP); 24 | int (*netNetEdgecount_ptr)(SEXP, int); 25 | int (*netNetSize_ptr)(SEXP); 26 | 27 | /*Modification functions*/ 28 | SEXP (*netAddEdge_ptr)(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); 29 | SEXP (*netAddEdges_ptr)(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); 30 | SEXP (*netDelEdgeAttrib_ptr)(SEXP, int, const char*); 31 | SEXP (*netDelNetAttrib_ptr)(SEXP, const char*); 32 | SEXP (*netDelVertexAttrib_ptr)(SEXP, int, const char*); 33 | SEXP (*netSetNetAttrib_ptr)(SEXP, const char*, SEXP); 34 | SEXP (*netSetVertexAttrib_ptr)(SEXP, const char*, SEXP, int); 35 | 36 | /*Access functions*/ 37 | #define netGetEdgeAttrib (*netGetEdgeAttrib_ptr) 38 | #define netGetEdgeIDs (*netGetEdgeIDs_ptr) 39 | #define netGetEdges (*netGetEdges_ptr) 40 | #define netGetNeighborhood (*netGetNeighborhood_ptr) 41 | #define netGetNetAttrib (*netGetNetAttrib_ptr) 42 | #define netHasLoops (*netHasLoops_ptr) 43 | #define netIsAdj (*netIsAdj_ptr) 44 | #define netIsDir (*netIsDir_ptr) 45 | #define netIsHyper (*netIsHyper_ptr) 46 | #define netIsLoop (*netIsLoop_ptr) 47 | #define netIsMulti (*netIsMulti_ptr) 48 | #define netIsNetwork (*netIsNetwork_ptr) 49 | #define netNetEdgecount (*netNetEdgecount_ptr) 50 | #define netNetSize (*netNetSize_ptr) 51 | 52 | /*Modification functions*/ 53 | #define netAddEdge (*netAddEdge_ptr) 54 | #define netAddEdges (*netAddEdges_ptr) 55 | #define netDelEdgeAttrib (*netDelEdgeAttrib_ptr) 56 | #define netDelNetAttrib (*netDelNetAttrib_ptr) 57 | #define netDelVertexAttrib (*netDelVertexAttrib_ptr) 58 | #define netSetNetAttrib (*netSetNetAttrib_ptr) 59 | #define netSetVertexAttrib (*netSetVertexAttrib_ptr) 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /inst/network.api/networkapi.c: -------------------------------------------------------------------------------- 1 | /* 2 | ###################################################################### 3 | # 4 | # networkapi.c 5 | # 6 | # Written by Carter T. Butts 7 | # Last Modified 5/07/16 8 | # Licensed under the GNU General Public License version 2 (June, 1991) 9 | # or greater. 10 | # 11 | # Provides support for the R/network package API. 12 | # 13 | # This file is known to be compatible with network package version 1.14. 14 | # It should be compatible with subsequent versions, but updates may be 15 | # necessary in rare cases. 16 | # 17 | # This file contains the registration routine needed to use the 18 | # C-level network package API. 19 | # 20 | ###################################################################### 21 | */ 22 | 23 | /*INCLUSIONS----------------------------------------------------------------*/ 24 | 25 | #include 26 | #include 27 | #include "networkapi.h" 28 | 29 | 30 | /*INTERNAL FUNCTIONS--------------------------------------------------------*/ 31 | 32 | void netRegisterFunctions(void) 33 | /*Register functions for the network package API. This function must be called before using any API routines, since these routines will not otherwise be defined within the local namespace.*/ 34 | { 35 | /*Register access routines*/ 36 | netGetEdgeAttrib_ptr = (SEXP (*)(SEXP, int, const char*)) R_GetCCallable("network", "getEdgeAttribute"); 37 | netGetEdgeIDs_ptr = (SEXP (*)(SEXP, int, int, const char*, int)) R_GetCCallable("network", "getEdgeIDs"); 38 | netGetEdges_ptr = (SEXP (*)(SEXP, int, int, const char*, int)) R_GetCCallable("network", "getEdges"); 39 | netGetNeighborhood_ptr = (SEXP (*)(SEXP, int, const char*, int)) R_GetCCallable("network", "getNeighborhood"); 40 | netGetNetAttrib_ptr = (SEXP (*)(SEXP, const char*)) R_GetCCallable("network", "getNetworkAttribute"); 41 | netHasLoops_ptr = (int (*)(SEXP)) R_GetCCallable("network", "hasLoops"); 42 | netIsAdj_ptr = (int (*)(SEXP, int, int, int)) R_GetCCallable("network", "isAdjacent"); 43 | netIsDir_ptr = (int (*)(SEXP)) R_GetCCallable("network", "isDirected"); 44 | netIsHyper_ptr = (int (*)(SEXP)) R_GetCCallable("network", "isHyper"); 45 | netIsLoop_ptr = (int (*)(SEXP, SEXP)) R_GetCCallable("network", "isLoop"); 46 | netIsMulti_ptr = (int (*)(SEXP)) R_GetCCallable("network", "isMultiplex"); 47 | netIsNetwork_ptr = (int (*)(SEXP)) R_GetCCallable("network", "isNetwork"); 48 | netNetEdgecount_ptr = (int (*)(SEXP, int)) R_GetCCallable("network", "networkEdgecount"); 49 | netNetSize_ptr = (int (*)(SEXP)) R_GetCCallable("network", "networkSize"); 50 | 51 | /*Register modification routines*/ 52 | netAddEdge_ptr = (SEXP (*)(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP)) R_GetCCallable("network", "addEdge_R"); 53 | netAddEdges_ptr = (SEXP (*)(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP)) R_GetCCallable("network", "addEdges_R"); 54 | netDelEdgeAttrib_ptr = (SEXP (*)(SEXP, int, const char*)) R_GetCCallable("network", "deleteEdgeAttribute"); 55 | netDelVertexAttrib_ptr = (SEXP (*)(SEXP, int, const char*)) R_GetCCallable("network", "deleteVertexAttribute"); 56 | netDelNetAttrib_ptr = (SEXP (*)(SEXP, const char*)) R_GetCCallable("network", "deleteNetworkAttribute"); 57 | netSetNetAttrib_ptr = (SEXP (*)(SEXP, const char*, SEXP)) R_GetCCallable("network", "setNetworkAttribute"); 58 | netSetVertexAttrib_ptr = (SEXP (*)(SEXP, const char*, SEXP, int)) R_GetCCallable("network", "setVertexAttribute"); 59 | 60 | 61 | -------------------------------------------------------------------------------- /inst/network.api/networkapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ###################################################################### 3 | # 4 | # networkapi.h 5 | # 6 | # Written by Carter T. Butts 7 | # Last Modified 5/07/16 8 | # Licensed under the GNU General Public License version 2 (June, 1991) 9 | # or greater. 10 | # 11 | # Provides support for the R/network package API. 12 | # 13 | # This file was written for network version 1.14. If using a later 14 | # version of network, you may need to update it. 15 | # 16 | # This file contains headers for networkapi.c, as well as macros and 17 | # other definitions needed to support the network package API. 18 | # 19 | ###################################################################### 20 | */ 21 | #ifndef NETWORKAPI_H 22 | #define NETWORKAPI_H 23 | 24 | 25 | /*INCLUSIONS----------------------------------------------------------------*/ 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | 33 | /*FUNCTION MACROS-----------------------------------------------------------*/ 34 | 35 | /*Access functions*/ 36 | #define netGetEdgeAttrib (*netGetEdgeAttrib_ptr) 37 | #define netGetEdgeIDs (*netGetEdgeIDs_ptr) 38 | #define netGetEdges (*netGetEdges_ptr) 39 | #define netGetNeighborhood (*netGetNeighborhood_ptr) 40 | #define netGetNetAttrib (*netGetNetAttrib_ptr) 41 | #define netHasLoops (*netHasLoops_ptr) 42 | #define netIsAdj (*netIsAdj_ptr) 43 | #define netIsDir (*netIsDir_ptr) 44 | #define netIsHyper (*netIsHyper_ptr) 45 | #define netIsLoop (*netIsLoop_ptr) 46 | #define netIsMulti (*netIsMulti_ptr) 47 | #define netIsNetwork (*netIsNetwork_ptr) 48 | #define netNetEdgecount (*netNetEdgecount_ptr) 49 | #define netNetSize (*netNetSize_ptr) 50 | 51 | /*Modification functions*/ 52 | #define netAddEdge (*netAddEdge_ptr) 53 | #define netAddEdges (*netAddEdges_ptr) 54 | #define netDelEdgeAttrib (*netDelEdgeAttrib_ptr) 55 | #define netDelNetAttrib (*netDelNetAttrib_ptr) 56 | #define netDelVertexAttrib (*netDelVertexAttrib_ptr) 57 | #define netSetNetAttrib (*netSetNetAttrib_ptr) 58 | #define netSetVertexAttrib (*netSetVertexAttrib_ptr) 59 | 60 | 61 | /*POINTER VARIABLES---------------------------------------------------------*/ 62 | 63 | /*Access functions*/ 64 | SEXP (*netGetEdgeAttrib_ptr)(SEXP, int, const char*); 65 | SEXP (*netGetEdgeIDs_ptr)(SEXP, int, int, const char*, int); 66 | SEXP (*netGetEdges_ptr)(SEXP, int, int, const char*, int); 67 | SEXP (*netGetNeighborhood_ptr)(SEXP, int, const char*, int); 68 | SEXP (*netGetNetAttrib_ptr)(SEXP, const char*); 69 | int (*netHasLoops_ptr)(SEXP); 70 | int (*netIsAdj_ptr)(SEXP, int, int, int); 71 | int (*netIsDir_ptr)(SEXP); 72 | int (*netIsHyper_ptr)(SEXP); 73 | int (*netIsLoop_ptr)(SEXP, SEXP); 74 | int (*netIsMulti_ptr)(SEXP); 75 | int (*netIsNetwork_ptr)(SEXP); 76 | int (*netNetEdgecount_ptr)(SEXP, int); 77 | int (*netNetSize_ptr)(SEXP); 78 | 79 | /*Modification functions*/ 80 | SEXP (*netAddEdge_ptr)(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); 81 | SEXP (*netAddEdges_ptr)(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); 82 | SEXP (*netDelEdgeAttrib_ptr)(SEXP, int, const char*); 83 | SEXP (*netDelNetAttrib_ptr)(SEXP, const char*); 84 | SEXP (*netDelVertexAttrib_ptr)(SEXP, int, const char*); 85 | SEXP (*netSetNetAttrib_ptr)(SEXP, const char*, SEXP); 86 | SEXP (*netSetVertexAttrib_ptr)(SEXP, const char*, SEXP, int); 87 | 88 | 89 | /*REGISTRATION FUNCTIONS----------------------------------------------------*/ 90 | 91 | void netRegisterFunctions(void); 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /man/add.edges.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/access.R 3 | \name{add.edges} 4 | \alias{add.edges} 5 | \alias{add.edge} 6 | \alias{add.edges.network} 7 | \alias{add.edge.network} 8 | \title{Add Edges to a Network Object} 9 | \usage{ 10 | add.edge( 11 | x, 12 | tail, 13 | head, 14 | names.eval = NULL, 15 | vals.eval = NULL, 16 | edge.check = FALSE, 17 | ... 18 | ) 19 | 20 | add.edges(x, tail, head, names.eval = NULL, vals.eval = NULL, ...) 21 | } 22 | \arguments{ 23 | \item{x}{an object of class \code{network}} 24 | 25 | \item{tail}{for \code{add.edge}, a vector of vertex IDs reflecting the tail 26 | set for the edge to be added; for \code{add.edges}, a list of such vectors} 27 | 28 | \item{head}{for \code{add.edge}, a vector of vertex IDs reflecting the head 29 | set for the edge to be added; for \code{add.edges}, a list of such vectors} 30 | 31 | \item{names.eval}{for \code{add.edge}, an optional list of names for edge 32 | attributes; for \code{add.edges}, a list of length equal to the number of 33 | edges, with each element containing a list of names for the attributes of 34 | the corresponding edge} 35 | 36 | \item{vals.eval}{for \code{add.edge}, an optional list of edge attribute 37 | values (matching \code{names.eval}); for \code{add.edges}, a list of such 38 | lists} 39 | 40 | \item{edge.check}{logical; should we perform (computationally expensive) 41 | tests to check for the legality of submitted edges?} 42 | 43 | \item{...}{additional arguments} 44 | } 45 | \value{ 46 | Invisibly, \code{add.edge} and \code{add.edges} return pointers to 47 | their modified arguments; both functions modify their arguments in place.. 48 | } 49 | \description{ 50 | Add one or more edges to an existing network object. 51 | } 52 | \details{ 53 | The edge checking procedure is very slow, but should always be employed when 54 | debugging; without it, one cannot guarantee that the network state is 55 | consistent with network level variables (see 56 | \code{\link{network.indicators}}). For example, by default it is possible to 57 | add multiple edges to a pair of vertices. 58 | 59 | Edges can also be added/removed via the extraction/replacement operators. 60 | See the associated man page for details. 61 | } 62 | \note{ 63 | \code{add.edges} and \code{add.edge} were converted to an S3 generic 64 | funtions in version 1.9, so they actually call \code{add.edges.network} and 65 | \code{add.edge.network} by default, and may call other versions depending on 66 | context (i.e. when called with a \code{networkDynamic} object). 67 | } 68 | \examples{ 69 | 70 | #Initialize a small, empty network 71 | g<-network.initialize(3) 72 | 73 | #Add an edge 74 | add.edge(g,1,2) 75 | g 76 | 77 | #Can also add edges using the extraction/replacement operators 78 | #note that replacement operators are much slower than add.edges() 79 | g[,3]<-1 80 | g[,] 81 | 82 | #Add multiple edges with attributes to a network 83 | 84 | # pretend we just loaded in this data.frame from a file 85 | # Note: network.edgelist() may be simpler for this case 86 | elData<-data.frame( 87 | from_id=c("1","2","3","1","3","1","2"), 88 | to_id=c("1", "1", "1", "2", "2", "3", "3"), 89 | myEdgeWeight=c(1, 2, 1, 2, 5, 3, 9.5), 90 | someLetters=c("B", "W", "L", "Z", "P", "Q", "E"), 91 | edgeCols=c("red","green","blue","orange","pink","brown","gray"), 92 | stringsAsFactors=FALSE 93 | ) 94 | 95 | valueNet<-network.initialize(3,loops=TRUE) 96 | 97 | add.edges(valueNet,elData[,1],elData[,2], 98 | names.eval=rep(list(list("myEdgeWeight","someLetters","edgeCols")),nrow(elData)), 99 | vals.eval=lapply(1:nrow(elData),function(r){as.list(elData[r,3:5])})) 100 | 101 | list.edge.attributes(valueNet) 102 | 103 | 104 | } 105 | \references{ 106 | Butts, C. T. (2008). \dQuote{network: a Package for Managing 107 | Relational Data in R.} \emph{Journal of Statistical Software}, 24(2). 108 | \doi{10.18637/jss.v024.i02} 109 | } 110 | \seealso{ 111 | \code{\link{network}}, \code{\link{add.vertices}}, 112 | \code{\link{network.extraction}}, \code{\link{delete.edges}}, 113 | \code{\link{network.edgelist}} 114 | } 115 | \author{ 116 | Carter T. Butts \email{buttsc@uci.edu} 117 | } 118 | \keyword{classes} 119 | \keyword{graphs} 120 | -------------------------------------------------------------------------------- /man/add.vertices.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/access.R 3 | \name{add.vertices} 4 | \alias{add.vertices} 5 | \alias{add.vertices.network} 6 | \title{Add Vertices to an Existing Network} 7 | \usage{ 8 | add.vertices(x, nv, vattr = NULL, last.mode = TRUE, ...) 9 | } 10 | \arguments{ 11 | \item{x}{an object of class \code{network}} 12 | 13 | \item{nv}{the number of vertices to add} 14 | 15 | \item{vattr}{optionally, a list of attributes with one entry per new vertex} 16 | 17 | \item{last.mode}{logical; should the new vertices be added to the last 18 | (rather than the first) mode of a bipartite network?} 19 | 20 | \item{...}{possible additional arguments to add.vertices} 21 | } 22 | \value{ 23 | Invisibly, a pointer to the updated \code{network} object; 24 | \code{add.vertices} modifies its argument in place. 25 | } 26 | \description{ 27 | \code{add.vertices} adds a specified number of vertices to an existing 28 | network; if desired, attributes for the new vertices may be specified as 29 | well. 30 | } 31 | \details{ 32 | New vertices are generally appended to the end of the network (i.e., their 33 | vertex IDs begin with \code{network.size(x)} an count upward). The one 34 | exception to this rule is when \code{x} is bipartite and 35 | \code{last.mode==FALSE}. In this case, new vertices are added to the end of 36 | the first mode, with existing second-mode vertices being permuted upward in 37 | ID. (\code{x}'s \code{bipartite} attribute is adjusted accordingly.) 38 | 39 | Note that the attribute format used here is based on the internal 40 | (vertex-wise) storage method, as opposed to the attribute-wise format used 41 | by \code{\link{network}}. Specifically, \code{vattr} should be a list with 42 | one entry per new vertex, the ith element of which should be a list with an 43 | element for every attribute of the ith vertex. (If the required \code{na} 44 | attribute is not given, it will be automatically created.) 45 | } 46 | \note{ 47 | \code{add.vertices} was converted to an S3 generic funtion in version 48 | 1.9, so it actually calls \code{add.vertices.network} by default and may 49 | call other versions depending on context (i.e. when called with a 50 | \code{networkDynamic} object). 51 | } 52 | \examples{ 53 | 54 | #Initialize a network object 55 | g<-network.initialize(5) 56 | g 57 | 58 | #Add five more vertices 59 | add.vertices(g,5) 60 | g 61 | 62 | #Create two more, with attributes 63 | vat<-replicate(2,list(is.added=TRUE,num.added=2),simplify=FALSE) 64 | add.vertices(g,2,vattr=vat) 65 | g\%v\%"is.added" #Values are only present for the new cases 66 | g\%v\%"num.added" 67 | 68 | #Add to a bipartite network 69 | bip <-network.initialize(5,bipartite=3) 70 | get.network.attribute(bip,'bipartite') # how many vertices in first mode? 71 | add.vertices(bip,3,last.mode=FALSE) 72 | get.network.attribute(bip,'bipartite') 73 | 74 | } 75 | \references{ 76 | Butts, C. T. (2008). \dQuote{network: a Package for Managing 77 | Relational Data in R.} \emph{Journal of Statistical Software}, 24(2). 78 | \doi{10.18637/jss.v024.i02} 79 | } 80 | \seealso{ 81 | \code{\link{network}}, \code{\link{get.vertex.attribute}}, 82 | \code{\link{set.vertex.attribute}} 83 | } 84 | \author{ 85 | Carter T. Butts \email{buttsc@uci.edu} 86 | } 87 | \keyword{classes} 88 | \keyword{graphs} 89 | -------------------------------------------------------------------------------- /man/as.color.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/misc.R 3 | \name{as.color} 4 | \alias{as.color} 5 | \alias{is.color} 6 | \title{Transform vector of values into color specification} 7 | \usage{ 8 | as.color(x, opacity = 1) 9 | 10 | is.color(x) 11 | } 12 | \arguments{ 13 | \item{x}{vector of numeric, character or factor values to be transformed} 14 | 15 | \item{opacity}{optional numeric value in the range 0.0 to 1.0 used to specify 16 | the opacity/transparency (alpha) of the colors to be returned. 0 means 17 | fully opaque, 1 means fully transparent. 18 | 19 | Behavior of \code{as.color} is as follows: \itemize{ \item integer numeric 20 | values: unchanged, (assumed to corespond to values of R's active 21 | \code{\link{palette}}) \item integer real values: will be translated to into 22 | grayscale values ranging between the max and min \item factor: integer 23 | values corresponding to factor levels will be used \item character: if 24 | values are valid colors (as determined by \code{is.color}) they will be 25 | returned as is. Otherwise converted to factor and numeric value of factor 26 | returned. } 27 | 28 | The optional \code{opacity} parameter can be used to make colors partially 29 | transparent (as a shortcut for \code{\link{adjustcolor}}. If used, colors 30 | will be returned as hex rgb color string (i.e. \code{"#00FF0080"}) 31 | 32 | The \code{is.color} function checks if each character element of \code{x} 33 | appears to be a color name by comparing it to \code{\link{colors}} and 34 | checking if it is an HTML-style hex color code. Note that it will return 35 | FALSE for integer values. 36 | 37 | These functions are used for the color parameters of 38 | \code{\link{plot.network}}.} 39 | } 40 | \value{ 41 | For \code{as.color}, a vector integer values (corresponding to color 42 | palette values) or character color name. For \code{is.color}, a logical 43 | vector indicating if each element of x appears to be a color 44 | 45 | \code{as.color()} returns TRUE if x is a character in a known color format. 46 | } 47 | \description{ 48 | Convenience function to convert a vector of values into a color 49 | specification. 50 | } 51 | \examples{ 52 | 53 | 54 | as.color(1:3) 55 | as.color(c('a','b','c')) 56 | 57 | # add some transparency 58 | as.color(c('red','green','blue'),0.5) # gives "#FF000080", "#00FF0080", "#0000FF80" 59 | 60 | is.color(c('red',1,'foo',NA,'#FFFFFF55')) 61 | } 62 | -------------------------------------------------------------------------------- /man/as.data.frame.network.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/dataframe.R 3 | \name{as.data.frame.network} 4 | \alias{as.data.frame.network} 5 | \title{Coerce a Network Object to a \code{data.frame}} 6 | \usage{ 7 | \method{as.data.frame}{network}( 8 | x, 9 | ..., 10 | unit = c("edges", "vertices"), 11 | na.rm = TRUE, 12 | attrs_to_ignore = "na", 13 | name_vertices = TRUE, 14 | sort_attrs = FALSE, 15 | store_eid = FALSE 16 | ) 17 | } 18 | \arguments{ 19 | \item{x}{an object of class \code{network}} 20 | 21 | \item{...}{additional arguments} 22 | 23 | \item{unit}{whether a \code{data.frame} of edge or vertex 24 | attributes should be returned.} 25 | 26 | \item{na.rm}{logical; ignore missing edges/vertices when constructing the 27 | data frame?} 28 | 29 | \item{attrs_to_ignore}{character; a vector of attribute names to 30 | exclude from the returned \code{data.frame} (Default: 31 | \code{"na"})} 32 | 33 | \item{name_vertices}{logical; for \code{unit="edges"}, should the 34 | \code{.tail} and the \code{.head} columns contain vertex names as opposed 35 | to vertex indices?} 36 | 37 | \item{sort_attrs}{logical; should the attribute columns in the 38 | returned data frame be sorted alphabetically?} 39 | 40 | \item{store_eid}{logical; for \code{unit="edges"}, should the edge ID in 41 | the network's internal representation be stored in a column 42 | \code{.eid}?} 43 | } 44 | \description{ 45 | The \code{as.data.frame} method coerces its input to a \code{data.frame} containing 46 | \code{x}'s edges or vertices. 47 | } 48 | -------------------------------------------------------------------------------- /man/as.edgelist.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/as.edgelist.R 3 | \name{as.edgelist} 4 | \alias{as.edgelist} 5 | \alias{as.edgelist.network} 6 | \alias{edgelist} 7 | \alias{as.edgelist.matrix} 8 | \alias{as.edgelist.tbl_df} 9 | \alias{is.edgelist} 10 | \title{Convert a network object into a numeric edgelist matrix} 11 | \usage{ 12 | \method{as.edgelist}{network}( 13 | x, 14 | attrname = NULL, 15 | as.sna.edgelist = FALSE, 16 | output = c("matrix", "tibble"), 17 | ... 18 | ) 19 | 20 | \method{as.edgelist}{matrix}( 21 | x, 22 | n, 23 | directed = TRUE, 24 | bipartite = FALSE, 25 | loops = FALSE, 26 | vnames = seq_len(n), 27 | ... 28 | ) 29 | 30 | \method{as.edgelist}{tbl_df}( 31 | x, 32 | n, 33 | directed = TRUE, 34 | bipartite = FALSE, 35 | loops = FALSE, 36 | vnames = seq_len(n), 37 | ... 38 | ) 39 | 40 | is.edgelist(x) 41 | } 42 | \arguments{ 43 | \item{x}{a \code{network} object with additional class added indicating how 44 | it should be dispatched.} 45 | 46 | \item{attrname}{optionally, the name of an edge attribute to use for edge 47 | values; may be a vector of names if \code{output="tibble"}} 48 | 49 | \item{as.sna.edgelist}{logical; should the edgelist be returned in edgelist 50 | form expected by the sna package? Ignored if \code{output="tibble"}} 51 | 52 | \item{output}{return type: a \code{\link{matrix}} or a \code{\link[tibble]{tibble}}; 53 | see \code{\link{as.matrix.network}} for the difference.} 54 | 55 | \item{\dots}{additional arguments to other methods} 56 | 57 | \item{n}{integer number of vertices in network, value passed to the 'n' flag 58 | on edgelist returned} 59 | 60 | \item{directed}{logical; is network directed, value passed to the 'directed' 61 | flag on edgelist returned} 62 | 63 | \item{bipartite}{logical or integer; is network bipartite, value passed to 64 | the 'bipartite' flag on edgelist returned} 65 | 66 | \item{loops}{logical; are self-loops allowed in network?, value passed to 67 | the 'loops' flag on edgelist returned} 68 | 69 | \item{vnames}{vertex names (defaults to vertex ids) to be attached to 70 | edgelist for sna package compatibility} 71 | } 72 | \value{ 73 | A matrix in which the first two columns are integers giving the tail 74 | (source) and head (target) vertex ids of each edge. The matrix will be given 75 | the class \code{edgelist}. 76 | 77 | The edgelist has additional attributes attached to it: \itemize{ \item 78 | \code{attr(,"n")} the number of vertices in the original network 79 | 80 | \item \code{attr(,"vnames")} the names of vertices in the original network 81 | 82 | \item \code{attr(,"directed")} logical, was the original network directed 83 | 84 | \item \code{attr(,"bipartite")} was the original network bipartite 85 | 86 | \item \code{attr(,"loops")} does the original network contain self-loops } 87 | 88 | Note that if the \code{attrname} attribute is used the resulting edgelist 89 | matrix will have three columns. And if \code{attrname} refers to a 90 | character attribute, the resulting edgelist matrix will be character rather 91 | than numeric unless \code{output="tibble"}. 92 | } 93 | \description{ 94 | Constructs an edgelist in a sorted format with defined attributes. 95 | } 96 | \details{ 97 | Constructs a edgelist matrix or tibble from a network, sorted tails-major 98 | order, with tails first, and, for undirected networks, tail < head. This 99 | format is required by some reverse-depending packages (e.g. \code{ergm}) 100 | 101 | The \code{\link{as.matrix.network.edgelist}} provides similar functionality 102 | but it does not enforce ordering or set the \code{edgelist} class and so 103 | should be slightly faster. 104 | 105 | \code{is.edgelist} tests if an object has the class \code{'edgelist'} 106 | } 107 | \note{ 108 | NOTE: this function was moved to network from the ergm package in 109 | network version 1.13 110 | } 111 | \examples{ 112 | 113 | data(emon) 114 | as.edgelist(emon[[1]]) 115 | as.edgelist(emon[[1]],output="tibble") 116 | # contrast with unsorted columns of 117 | as.matrix.network.edgelist(emon[[1]]) 118 | 119 | } 120 | \seealso{ 121 | See also \code{\link{as.matrix.network.edgelist}} 122 | } 123 | -------------------------------------------------------------------------------- /man/as.matrix.network.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/coercion.R 3 | \name{as.matrix.network} 4 | \alias{as.matrix.network} 5 | \alias{as.matrix.network.adjacency} 6 | \alias{as.matrix.network.edgelist} 7 | \alias{as_tibble.network} 8 | \alias{as.tibble.network} 9 | \alias{as.matrix.network.incidence} 10 | \title{Coerce a Network Object to Matrix or Table Form} 11 | \usage{ 12 | \method{as.matrix}{network}(x, matrix.type = NULL, attrname = NULL, ...) 13 | 14 | \method{as.matrix.network}{adjacency}(x, attrname=NULL, 15 | expand.bipartite = FALSE, ...) 16 | 17 | \method{as.matrix.network}{edgelist}(x, attrname=NULL, 18 | as.sna.edgelist = FALSE, na.rm = TRUE, ...) 19 | 20 | \method{as_tibble}{network}( 21 | x, 22 | attrnames = (match.arg(unit) == "vertices"), 23 | na.rm = TRUE, 24 | ..., 25 | unit = c("edges", "vertices"), 26 | store.eid = FALSE 27 | ) 28 | 29 | as.tibble.network( 30 | x, 31 | attrnames = (match.arg(unit) == "vertices"), 32 | na.rm = TRUE, 33 | ..., 34 | unit = c("edges", "vertices"), 35 | store.eid = FALSE 36 | ) 37 | 38 | \method{as.matrix.network}{incidence}(x, attrname=NULL, ...) 39 | } 40 | \arguments{ 41 | \item{x}{an object of class \code{network}} 42 | 43 | \item{matrix.type}{one of \code{"adjacency"}, \code{"incidence"}, 44 | \code{"edgelist"}, or \code{NULL}} 45 | 46 | \item{attrname}{optionally, the name of an edge attribute to use for edge 47 | values} 48 | 49 | \item{...}{additional arguments.} 50 | 51 | \item{expand.bipartite}{logical; if \code{x} is bipartite, should we return 52 | the full adjacency matrix (rather than the abbreviated, two-mode form)?} 53 | 54 | \item{as.sna.edgelist}{logical; should the edgelist be returned in sna 55 | edglist form?} 56 | 57 | \item{na.rm}{logical; should missing edges/vertices be included in the 58 | edgelist formats? Ignored if \code{as.sna.edgelist=TRUE}.} 59 | 60 | \item{attrnames}{optionally, either a character vector of the names of edge 61 | attributes to use for edge values, or a numerical or logical vector to use 62 | as indices for selecting them from \code{\link{list.edge.attributes}(x)} or 63 | \code{\link{list.vertex.attributes}(x)} (depending on \code{unit}); passing 64 | \code{TRUE} therefore returns all edge attributes as columns} 65 | 66 | \item{unit}{whether a \code{\link[tibble]{tibble}} of edge or vertex attributes 67 | should be returned.} 68 | 69 | \item{store.eid}{whether the edge ID should be stored in the third column (\code{.eid}).} 70 | } 71 | \value{ 72 | For \code{as.matrix} methods, an adjacency, incidence, or edgelist 73 | matrix. For the \code{as_tibble} method, a \code{tibble} whose first two 74 | columns are \code{.head} and \code{.tail}, whose third column \code{.eid} is 75 | the edge ID, and whose subsequent columns are the requested edge attributes. 76 | } 77 | \description{ 78 | The \code{as.matrix} methods attempt to coerce their input to a matrix in 79 | adjacency, incidence, or edgelist form. Edge values (from a stored 80 | attribute) may be used if present. \code{\link[tibble:as_tibble]{as_tibble}} 81 | coerces into an edgelist in \code{\link[tibble]{tibble}} (a type of 82 | \code{\link{data.frame}}) form; this can be especially useful if extrecting 83 | a character-type edge attribute. 84 | } 85 | \details{ 86 | If no matrix type is specified, \code{\link{which.matrix.type}} will be used 87 | to make an educated guess based on the shape of \code{x}. Where edge values 88 | are not specified, a dichotomous matrix will be assumed. 89 | 90 | Edgelists returned by the \code{as.matrix} methods are by default in a 91 | slightly different form from the \code{sna} edgelist standard, but do 92 | contain the \code{sna} extended matrix attributes (see 93 | \code{\link{as.network.matrix}}). They should typically be compatible with 94 | \code{sna} library functions. To ensure compatibility, the 95 | \code{as.sna.edgelist} argument can be set (which returns an exact 96 | \code{sna} edgelist). The \code{\link{as.edgelist}} function also returns a 97 | similar edgelist matrix but with an enforced sorting. 98 | 99 | For the \code{as.matrix} methods, if the \code{attrname} attribute is used 100 | to include a charcter attribute, the resulting edgelist matrix will be 101 | character rather than numeric. The \code{as_tibble} methods never coerce. 102 | 103 | Note that adjacency matrices may also be obtained using the extraction 104 | operator. See the relevant man page for details. Also note that which 105 | attributes get returned by the \code{as_tibble} method by default depends on 106 | \code{unit}: by default no edge attributes are returned but all vertex 107 | attributes are. 108 | } 109 | \examples{ 110 | 111 | # Create a random network 112 | m <- matrix(rbinom(25,4,0.159),5,5) # 50\% density 113 | diag(m) <- 0 114 | g <- network(m, ignore.eval=FALSE, names.eval="a") # With values 115 | g \%e\% "ac" <- letters[g \%e\% "a"] 116 | 117 | # Coerce to matrix form 118 | # No attributes: 119 | as.matrix(g,matrix.type="adjacency") 120 | as.matrix(g,matrix.type="incidence") 121 | as.matrix(g,matrix.type="edgelist") 122 | # Attributes: 123 | as.matrix(g,matrix.type="adjacency",attrname="a") 124 | as.matrix(g,matrix.type="incidence",attrname="a") 125 | as.matrix(g,matrix.type="edgelist",attrname="a") 126 | as.matrix(g,matrix.type="edgelist",attrname="ac") 127 | 128 | # Coerce to a tibble: 129 | library(tibble) 130 | as_tibble(g) 131 | as_tibble(g, attrnames=c("a","ac")) 132 | as_tibble(g, attrnames=TRUE) 133 | # Get vertex attributes instead: 134 | as_tibble(g, unit = "vertices") 135 | 136 | # Missing data handling: 137 | g[1,2] <- NA 138 | as.matrix(g,matrix.type="adjacency") # NA in the corresponding cell 139 | as.matrix(g,matrix.type="edgelist", na.rm=TRUE) # (1,2) excluded 140 | as.matrix(g,matrix.type="edgelist", na.rm=FALSE) # (1,2) included 141 | as_tibble(g, attrnames="na", na.rm=FALSE) # Which edges are marked missing? 142 | 143 | # Can also use the extraction operator 144 | g[,] # Get entire adjacency matrix 145 | g[1:2,3:5] # Obtain a submatrix 146 | 147 | } 148 | \references{ 149 | Butts, C. T. (2008). \dQuote{network: a Package for Managing 150 | Relational Data in R.} \emph{Journal of Statistical Software}, 24(2). 151 | \doi{10.18637/jss.v024.i02} 152 | } 153 | \seealso{ 154 | \code{\link{which.matrix.type}}, \code{\link{network}}, 155 | \code{\link{network.extraction}},\code{\link{as.edgelist}} 156 | } 157 | \author{ 158 | Carter T. Butts \email{buttsc@uci.edu} and David Hunter 159 | \email{dhunter@stat.psu.edu} 160 | } 161 | \keyword{classes} 162 | \keyword{graphs} 163 | -------------------------------------------------------------------------------- /man/as.network.matrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/coercion.R 3 | \name{as.network.matrix} 4 | \alias{as.network.matrix} 5 | \alias{as.network.default} 6 | \title{Coercion from Matrices to Network Objects} 7 | \usage{ 8 | \method{as.network}{default}(x, ...) 9 | 10 | \method{as.network}{matrix}( 11 | x, 12 | matrix.type = NULL, 13 | directed = TRUE, 14 | hyper = FALSE, 15 | loops = FALSE, 16 | multiple = FALSE, 17 | bipartite = FALSE, 18 | ignore.eval = TRUE, 19 | names.eval = NULL, 20 | na.rm = FALSE, 21 | edge.check = FALSE, 22 | ... 23 | ) 24 | } 25 | \arguments{ 26 | \item{x}{a matrix containing an adjacency structure} 27 | 28 | \item{...}{additional arguments} 29 | 30 | \item{matrix.type}{one of \code{"adjacency"}, \code{"edgelist"}, 31 | \code{"incidence"}, or \code{NULL}} 32 | 33 | \item{directed}{logical; should edges be interpreted as directed?} 34 | 35 | \item{hyper}{logical; are hyperedges allowed?} 36 | 37 | \item{loops}{logical; should loops be allowed?} 38 | 39 | \item{multiple}{logical; are multiplex edges allowed?} 40 | 41 | \item{bipartite}{count; should the network be interpreted as bipartite? If 42 | present (i.e., non-NULL) it is the count of the number of actors in the 43 | bipartite network. In this case, the number of nodes is equal to the number 44 | of actors plus the number of events (with all actors preceding all events). 45 | The edges are then interpreted as nondirected.} 46 | 47 | \item{ignore.eval}{logical; ignore edge values?} 48 | 49 | \item{names.eval}{optionally, the name of the attribute in which edge values 50 | should be stored} 51 | 52 | \item{na.rm}{logical; ignore missing entries when constructing the network?} 53 | 54 | \item{edge.check}{logical; perform consistency checks on new edges?} 55 | } 56 | \value{ 57 | An object of class \code{network} 58 | } 59 | \description{ 60 | \code{as.network.matrix} attempts to coerce its first argument to an object 61 | of class \code{network}. 62 | } 63 | \details{ 64 | Depending on \code{matrix.type}, one of three edgeset constructor methods 65 | will be employed to read the input matrix (see 66 | \code{\link{edgeset.constructors}}). If \code{matrix.type==NULL}, 67 | \code{\link{which.matrix.type}} will be used to guess the appropriate matrix 68 | type. 69 | 70 | The coercion methods will recognize and attempt to utilize the \code{sna} 71 | extended matrix attributes where feasible. These are as follows: \itemize{ 72 | \item\code{"n"}: taken to indicate number of vertices in the network. 73 | \item\code{"bipartite"}: taken to indicate the network's \code{bipartite} 74 | attribute, where present. \item\code{"vnames"}: taken to contain vertex 75 | names, where present. } These attributes are generally used with edgelists, 76 | and indeed data in \code{sna} edgelist format should be transparently 77 | converted in most cases. Where the extended matrix attributes are in 78 | conflict with the actual contents of \code{x}, results are no guaranteed 79 | (but the latter will usually override the former). For an edge list, the 80 | number of nodes in a network is determined by the number of unique nodes 81 | specified. If there are isolate nodes not in the edge list, the "n" 82 | attribute needs to be set. See example below. 83 | } 84 | \examples{ 85 | 86 | #Draw a random matrix 87 | m<-matrix(rbinom(25,1,0.5),5) 88 | diag(m)<-0 89 | 90 | #Coerce to network form 91 | g<-as.network.matrix(m,matrix.type="adjacency") 92 | 93 | # edge list example. Only 4 nodes in the edge list. 94 | m = matrix(c(1,2, 2,3, 3,4), byrow = TRUE, nrow=3) 95 | attr(m, 'n') = 7 96 | as.network(m, matrix.type='edgelist') 97 | 98 | } 99 | \references{ 100 | Butts, C. T. (2008). \dQuote{network: a Package for Managing 101 | Relational Data in R.} \emph{Journal of Statistical Software}, 24(2). 102 | \doi{10.18637/jss.v024.i02} 103 | } 104 | \seealso{ 105 | \code{\link{edgeset.constructors}}, \code{\link{network}}, 106 | \code{\link{which.matrix.type}} 107 | } 108 | \author{ 109 | Carter T. Butts \email{buttsc@uci.edu} and David Hunter 110 | \email{dhunter@stat.psu.edu} 111 | } 112 | \keyword{classes} 113 | \keyword{graphs} 114 | -------------------------------------------------------------------------------- /man/as.sociomatrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/coercion.R 3 | \name{as.sociomatrix} 4 | \alias{as.sociomatrix} 5 | \title{Coerce One or More Networks to Sociomatrix Form} 6 | \usage{ 7 | as.sociomatrix( 8 | x, 9 | attrname = NULL, 10 | simplify = TRUE, 11 | expand.bipartite = FALSE, 12 | ... 13 | ) 14 | } 15 | \arguments{ 16 | \item{x}{an adjacency matrix, array, \code{\link{network}} object, or list 17 | thereof.} 18 | 19 | \item{attrname}{optionally, the name of a network attribute to use for 20 | extracting edge values (if \code{x} is a \code{\link{network}} object).} 21 | 22 | \item{simplify}{logical; should \code{as.sociomatrix} attempt to combine its 23 | inputs into an adjacency array (\code{TRUE}), or return them as separate 24 | list elements (\code{FALSE})?} 25 | 26 | \item{expand.bipartite}{logical; if \code{x} is bipartite, should we return 27 | the full adjacency matrix (rather than the abbreviated, two-mode form)?} 28 | 29 | \item{...}{additional arguments for the coercion routine.} 30 | } 31 | \value{ 32 | One or more adjacency matrices. If all matrices are of the same 33 | dimension and \code{simplify==TRUE}, the matrices are joined into a single 34 | array; otherwise, the return value is a list of single adjacency matrices. 35 | } 36 | \description{ 37 | \code{as.sociomatrix} takes adjacency matrices, adjacency arrays, 38 | \code{\link{network}} objects, or lists thereof, and returns one or more 39 | sociomatrices (adjacency matrices) as appropriate. This routine provides a 40 | useful input-agnostic front-end to functions which process adjacency 41 | matrices. 42 | } 43 | \details{ 44 | \code{as.sociomatrix} provides a more general means of coercing input into 45 | adjacency matrix form than \code{\link{as.matrix.network}}. In particular, 46 | \code{as.sociomatrix} will attempt to coerce all input networks into the 47 | appropriate form, and return the resulting matrices in a regularized manner. 48 | If \code{simplify==TRUE}, \code{as.sociomatrix} attempts to return the 49 | matrices as a single adjacency array. If the input networks are of variable 50 | size, or if \code{simplify==FALSE}, the networks in question are returned as 51 | a list of matrices. In any event, a single input network is always returned 52 | as a lone matrix. 53 | 54 | If \code{attrname} is given, the specified edge attribute is used to extract 55 | edge values from any \code{\link{network}} objects contained in \code{x}. 56 | Note that the same attribute will be used for all networks; if no attribute 57 | is specified, the standard dichotomous default will be used instead. 58 | } 59 | \examples{ 60 | 61 | #Generate an adjacency array 62 | g<-array(rbinom(100,1,0.5),dim=c(4,5,5)) 63 | 64 | #Generate a network object 65 | net<-network(matrix(rbinom(36,1,0.5),6,6)) 66 | 67 | #Coerce to adjacency matrix form using as.sociomatrix 68 | as.sociomatrix(g,simplify=TRUE) #Returns as-is 69 | as.sociomatrix(g,simplify=FALSE) #Returns as list 70 | as.sociomatrix(net) #Coerces to matrix 71 | as.sociomatrix(list(net,g)) #Returns as list of matrices 72 | 73 | } 74 | \references{ 75 | Butts, C. T. (2008). \dQuote{network: a Package for Managing 76 | Relational Data in R.} \emph{Journal of Statistical Software}, 24(2). 77 | \doi{10.18637/jss.v024.i02} 78 | } 79 | \seealso{ 80 | \code{\link{as.matrix.network}}, \code{\link{network}} 81 | } 82 | \author{ 83 | Carter T. Butts \email{buttsc@uci.edu} 84 | } 85 | \keyword{graphs} 86 | \keyword{manip} 87 | -------------------------------------------------------------------------------- /man/deletion.methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/access.R 3 | \name{deletion.methods} 4 | \alias{deletion.methods} 5 | \alias{delete.edges} 6 | \alias{delete.edges.network} 7 | \alias{delete.vertices} 8 | \alias{delete.vertices.network} 9 | \title{Remove Elements from a Network Object} 10 | \usage{ 11 | delete.edges(x, eid, ...) 12 | 13 | \method{delete.edges}{network}(x, eid, ...) 14 | 15 | delete.vertices(x, vid, ...) 16 | 17 | \method{delete.vertices}{network}(x, vid, ...) 18 | } 19 | \arguments{ 20 | \item{x}{an object of class \code{network}.} 21 | 22 | \item{eid}{a vector of edge IDs.} 23 | 24 | \item{...}{additional arguments to methods.} 25 | 26 | \item{vid}{a vector of vertex IDs.} 27 | } 28 | \value{ 29 | Invisibly, a pointer to the updated network; these functions modify 30 | their arguments in place. 31 | } 32 | \description{ 33 | \code{delete.edges} removes one or more edges (specified by 34 | their internal ID numbers) from a network; \code{delete.vertices} 35 | performs the same task for vertices (removing all associated edges in 36 | the process). 37 | } 38 | \details{ 39 | Note that an edge's ID number corresponds to its order within 40 | \code{x$mel}. To determine edge IDs, see \code{\link{get.edgeIDs}}. 41 | Likewise, vertex ID numbers reflect the order with which vertices are 42 | listed internally (e.g., the order of \code{x$oel} and \code{x$iel}, or 43 | that used by \code{as.matrix.network.adjacency}). When vertices are 44 | removed from a network, all edges having those vertices as endpoints are 45 | removed as well. When edges are removed, the remaining edge ids are NOT 46 | permuted and \code{NULL} elements will be left on the list of edges, which 47 | may complicate some functions that require eids (such as 48 | \code{\link{set.edge.attribute}}). The function \code{\link{valid.eids}} 49 | provides a means to determine the set of valid (non-NULL) edge ids. 50 | 51 | Edges can also be added/removed via the extraction/replacement operators. 52 | See the associated man page for details. 53 | } 54 | \examples{ 55 | #Create a network with three edges 56 | m<-matrix(0,3,3) 57 | m[1,2]<-1; m[2,3]<-1; m[3,1]<-1 58 | g<-network(m) 59 | 60 | as.matrix.network(g) 61 | delete.edges(g,2) #Remove an edge 62 | as.matrix.network(g) 63 | delete.vertices(g,2) #Remove a vertex 64 | as.matrix.network(g) 65 | 66 | #Can also remove edges using extraction/replacement operators 67 | g<-network(m) 68 | g[1,2]<-0 #Remove an edge 69 | g[,] 70 | g[,]<-0 #Remove all edges 71 | g[,] 72 | 73 | } 74 | \references{ 75 | Butts, C. T. (2008). \dQuote{network: a Package for Managing 76 | Relational Data in R.} \emph{Journal of Statistical Software}, 24(2). 77 | \doi{10.18637/jss.v024.i02} 78 | } 79 | \seealso{ 80 | \code{\link{get.edgeIDs}}, \code{\link{network.extraction}}, 81 | \code{\link{valid.eids}} 82 | } 83 | \author{ 84 | Carter T. Butts \email{buttsc@uci.edu} 85 | } 86 | \keyword{classes} 87 | \keyword{graphs} 88 | -------------------------------------------------------------------------------- /man/edgeset.constructors.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/constructors.R 3 | \name{edgeset.constructors} 4 | \alias{edgeset.constructors} 5 | \alias{network.bipartite} 6 | \alias{network.adjacency} 7 | \alias{network.edgelist} 8 | \alias{network.incidence} 9 | \title{Edgeset Constructors for Network Objects} 10 | \usage{ 11 | network.bipartite(x, g, ignore.eval = TRUE, names.eval = NULL, ...) 12 | 13 | network.adjacency(x, g, ignore.eval = TRUE, names.eval = NULL, ...) 14 | 15 | network.edgelist(x, g, ignore.eval = TRUE, names.eval = NULL, ...) 16 | 17 | network.incidence(x, g, ignore.eval = TRUE, names.eval = NULL, ...) 18 | } 19 | \arguments{ 20 | \item{x}{a matrix containing edge information} 21 | 22 | \item{g}{an object of class \code{network}} 23 | 24 | \item{ignore.eval}{logical; ignore edge value information in x?} 25 | 26 | \item{names.eval}{a name for the edge attribute under which to store edge 27 | values, if any} 28 | 29 | \item{\dots}{possible additional arguments (such as \code{edge.check})} 30 | } 31 | \value{ 32 | Invisibly, an object of class \code{network}; these functions modify 33 | their argument in place. 34 | } 35 | \description{ 36 | These functions convert relational data in matrix form to 37 | network edge sets. 38 | } 39 | \details{ 40 | Each of the above functions takes a \code{network} and a matrix 41 | as input, and modifies the supplied \code{network} object by adding the 42 | appropriate edges. \code{network.adjacency} takes \code{x} to be an 43 | adjacency matrix; \code{network.edgelist} takes \code{x} to be an edgelist 44 | matrix; and \code{network.incidence} takes \code{x} to be an incidence 45 | matrix. \code{network.bipartite} takes \code{x} to be a two-mode 46 | adjacency matrix where rows and columns reflect each respective mode 47 | (conventionally, actors and events); If \code{ignore.eval==FALSE}, 48 | (non-zero) edge values are stored as edgewise attributes with name 49 | \code{names.eval}. The \code{edge.check} argument can be added via 50 | \code{\dots} and will be passed to \code{\link{add.edges}}. 51 | 52 | Edgelist matrices to be used with \code{network.edgelist} should have one 53 | row per edge, with the first two columns indicating the sender and 54 | receiver of each edge (respectively). Edge values may be provided in 55 | additional columns. The edge attributes will be created with names 56 | corresponding to the column names unless alternate names are provided via 57 | \code{names.eval}. The vertices specified in the first two columns, which 58 | can be characters, are added to the network in default sort order. The 59 | edges are added in the order specified by the edgelist matrix. 60 | 61 | Incidence matrices should contain one row per vertex, with one column per 62 | edge. A non-zero entry in the matrix means that the edge with the id 63 | corresponding to the column index will have an incident vertex with an 64 | id corresponding to the row index. In the directed case, negative cell 65 | values are taken to indicate tail vertices, while positive values 66 | indicate head vertices. 67 | 68 | Results similar to \code{network.adjacency} can also be obtained by means 69 | of extraction/replacement operators. See the associated man page for 70 | details. 71 | } 72 | \examples{ 73 | #Create an arbitrary adjacency matrix 74 | m<-matrix(rbinom(25,1,0.5),5,5) 75 | diag(m)<-0 76 | 77 | g<-network.initialize(5) #Initialize the network 78 | network.adjacency(m,g) #Import the edge data 79 | 80 | #Do the same thing, using replacement operators 81 | g<-network.initialize(5) 82 | g[,]<-m 83 | 84 | # load edges from a data.frame via network.edgelist 85 | edata <-data.frame( 86 | tails=c(1,2,3), 87 | heads=c(2,3,1), 88 | love=c('yes','no','maybe'), 89 | hate=c(3,-5,2), 90 | stringsAsFactors=FALSE 91 | ) 92 | 93 | g<-network.edgelist(edata,network.initialize(4),ignore.eval=FALSE) 94 | as.sociomatrix(g,attrname='hate') 95 | g\%e\%'love' 96 | 97 | # load edges from an incidence matrix 98 | inci<-matrix(c(1,1,0,0, 0,1,1,0, 1,0,1,0),ncol=3,byrow=FALSE) 99 | inci 100 | g<-network.incidence(inci,network.initialize(4,directed=FALSE)) 101 | as.matrix(g) 102 | 103 | 104 | 105 | 106 | } 107 | \references{ 108 | Butts, C. T. (2008). \dQuote{network: a Package for Managing 109 | Relational Data in R.} \emph{Journal of Statistical Software}, 24(2). 110 | \doi{10.18637/jss.v024.i02} 111 | } 112 | \seealso{ 113 | \code{\link{loading.attributes}}, \code{\link{network}}, 114 | \code{\link{network.initialize}}, \code{\link{add.edges}}, 115 | \code{\link{network.extraction}} 116 | } 117 | \author{ 118 | Carter T. Butts \email{buttsc@uci.edu} and David Hunter 119 | \email{dhunter@stat.psu.edu} 120 | } 121 | \keyword{classes} 122 | \keyword{graphs} 123 | -------------------------------------------------------------------------------- /man/emon.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/network-package.R 3 | \docType{data} 4 | \name{emon} 5 | \alias{emon} 6 | \title{Interorganizational Search and Rescue Networks (Drabek et al.)} 7 | \format{ 8 | A list of 7 \code{\link{network}} objects: 9 | 10 | \tabular{rlll}{ 11 | \verb{[[1]]} \tab Cheyenne \tab network \tab Cheyenne SAR EMON\cr 12 | \verb{[[2]]} \tab HurrFrederic \tab network \tab Hurricane Frederic SAR EMON\cr 13 | \verb{[[3]]} \tab LakePomona \tab network \tab Lake Pomona SAR EMON\cr 14 | \verb{[[4]]} \tab MtSi \tab network \tab Mt. Si SAR EMON\cr 15 | \verb{[[5]]} \tab MtStHelens \tab network \tab Mt. St. Helens SAR EMON\cr 16 | \verb{[[6]]} \tab Texas \tab network \tab Texas Hill Country SAR EMON\cr 17 | \verb{[[7]]} \tab Wichita \tab network \tab Wichita Falls SAR EMON 18 | } 19 | 20 | Each network has one edge attribute: 21 | 22 | \tabular{lll}{ Frequency \tab numeric \tab Interaction frequency (1-4; 23 | 1=most frequent) } 24 | 25 | Each network also has 8 vertex attributes: 26 | 27 | \tabular{lll}{ 28 | Command.Rank.Score \tab numeric \tab Mean rank in the command structure\cr 29 | Decision.Rank.Score \tab numeric \tab Mean rank in the decision process\cr 30 | Formalization \tab numeric \tab Degree of formalization\cr 31 | Location \tab character \tab Location code\cr 32 | Paid.Staff \tab numeric \tab Number of paid staff\cr 33 | Sponsorship \tab character \tab Sponsorship type\cr 34 | vertex.names \tab character \tab Organization name\cr 35 | Volunteer.Staff \tab numeric \tab Number of volunteer staff 36 | } 37 | } 38 | \source{ 39 | Drabek, T.E.; Tamminga, H.L.; Kilijanek, T.S.; and Adams, C.R. 40 | (1981). \emph{Data from Managing Multiorganizational Emergency Responses: 41 | Emergent Search and Rescue Networks in Natural Disaster and Remote Area 42 | Settings.} Program on Technology, Environment, and Man Monograph 33. 43 | Institute for Behavioral Science, University of Colorado. 44 | } 45 | \usage{ 46 | data(emon) 47 | } 48 | \description{ 49 | Drabek et al. (1981) provide seven case studies of emergent 50 | multi-organizational networks (EMONs) in the context of search and rescue 51 | (SAR) activities. Networks of interaction frequency are reported, along 52 | with several organizational attributes. 53 | } 54 | \details{ 55 | All networks collected by Drabek et al. reflect reported frequency of 56 | organizational interaction during the search and rescue effort; the (i,j) 57 | edge constitutes i's report regarding interaction with j, with non-adjacent 58 | vertices reporting no contact. Frequency is rated on a four-point scale, 59 | with 1 indicating the highest frequency of interaction. (Response options: 60 | 1=\dQuote{continuously}, 2=\dQuote{about once an hour}, 3=\dQuote{every few 61 | hours}, 4=\dQuote{about once a day or less}) This is stored within the 62 | \code{"Frequency"} edge attribute. 63 | 64 | For each network, several covariates are recorded as vertex attributes: 65 | 66 | \describe{ 67 | \item{Command.Rank.Score}{ Mean (reversed) rank for the 68 | prominence of each organization in the command structure of the response, as 69 | judged by organizational informants.} 70 | \item{Decision.Rank.Score}{ Mean (reversed) rank for the 71 | prominence of each organization in decision making 72 | processes during the response, as judged by organizational informants.} 73 | \item{Formalization}{ An index of organizational formalization, ranging from 74 | 0 (least formalized) to 4 (most formalized).} \item{Localization}{ For each 75 | organization, \code{"L"} if the organization was sited locally to the impact 76 | area, \code{"NL"} if the organization was not sited near the impact area, 77 | \code{"B"} if the organization was sited at both local and non-local 78 | locations.} 79 | \item{Paid.Staff}{ Number of paid staff employed by each 80 | organization at the time of the response.} 81 | \item{Sponsorship}{ The level at which each organization 82 | was sponsored (e.g., \code{"City"}, \code{"County"}, 83 | \code{"State"}, \code{"Federal"}, and \code{"Private"}).} 84 | \item{vertex.names}{ The identity of each organization.} 85 | \item{Volunteer.Staff}{ Number of volunteer staff employed by each 86 | organization at the time of the response.} 87 | } 88 | 89 | Note that where intervals were given by the original source, midpoints have 90 | been substituted. For detailed information regarding data coding and 91 | procedures, see Drabek et al. (1981). 92 | } 93 | \examples{ 94 | 95 | data(emon) #Load the emon data set 96 | 97 | #Plot the EMONs 98 | par(mfrow=c(3,3)) 99 | for(i in 1:length(emon)) 100 | plot(emon[[i]],main=names(emon)[i],edge.lwd="Frequency") 101 | 102 | } 103 | \seealso{ 104 | \code{\link{network}} 105 | } 106 | \keyword{datasets} 107 | -------------------------------------------------------------------------------- /man/flo.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/network-package.R 3 | \name{flo} 4 | \alias{flo} 5 | \title{Florentine Wedding Data (Padgett)} 6 | \source{ 7 | Padgett, John F. (1994). \dQuote{Marriage and Elite Structure in 8 | Renaissance Florence, 1282-1500.} Paper delivered to the Social Science 9 | History Association. 10 | } 11 | \usage{ 12 | data(flo) 13 | } 14 | \description{ 15 | This is a data set of Padgett (1994), consisting of weddings among leading 16 | Florentine families. This data is stored in symmetric adjacency matrix 17 | form. 18 | } 19 | \examples{ 20 | 21 | data(flo) 22 | nflo<-network(flo,directed=FALSE) #Convert to network object form 23 | all(nflo[,]==flo) #Trust, but verify 24 | #A fancy display: 25 | plot(nflo,displaylabels=TRUE,boxed.labels=FALSE,label.cex=0.75) 26 | 27 | } 28 | \references{ 29 | Wasserman, S. and Faust, K. (1994) \emph{Social Network 30 | Analysis: Methods and Applications}, Cambridge: Cambridge University Press. 31 | } 32 | \seealso{ 33 | \code{\link{network}} 34 | } 35 | \keyword{datasets} 36 | -------------------------------------------------------------------------------- /man/get.edges.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/access.R 3 | \name{get.edges} 4 | \alias{get.edges} 5 | \alias{get.edgeIDs} 6 | \alias{get.dyads.eids} 7 | \title{Retrieve Edges or Edge IDs Associated with a Given Vertex} 8 | \usage{ 9 | get.edgeIDs( 10 | x, 11 | v, 12 | alter = NULL, 13 | neighborhood = c("out", "in", "combined"), 14 | na.omit = TRUE 15 | ) 16 | 17 | get.edges( 18 | x, 19 | v, 20 | alter = NULL, 21 | neighborhood = c("out", "in", "combined"), 22 | na.omit = TRUE 23 | ) 24 | 25 | get.dyads.eids( 26 | x, 27 | tails, 28 | heads, 29 | neighborhood = c("out", "in", "combined"), 30 | na.omit = TRUE 31 | ) 32 | } 33 | \arguments{ 34 | \item{x}{an object of class \code{network}} 35 | 36 | \item{v}{a vertex ID} 37 | 38 | \item{alter}{optionally, the ID of another vertex} 39 | 40 | \item{neighborhood}{an indicator for whether we are interested in in-edges, 41 | out-edges, or both (relative to \code{v}). defaults to \code{'combined'} for 42 | undirected networks} 43 | 44 | \item{na.omit}{logical; should we omit missing edges?} 45 | 46 | \item{tails}{a vector of vertex ID for the 'tails' (v) side of the dyad} 47 | 48 | \item{heads}{a vector of vertex ID for the 'heads' (alter) side of the dyad} 49 | } 50 | \value{ 51 | For \code{get.edges}, a list of edges. For \code{get.edgeIDs}, a 52 | vector of edge ID numbers. For \code{get.dyads.eids}, a list of edge IDs 53 | corresponding to the dyads defined by the vertex ids in \code{tails} and 54 | \code{heads} 55 | } 56 | \description{ 57 | \code{get.edges} retrieves a list of edges incident on a given vertex; 58 | \code{get.edgeIDs} returns the internal identifiers for those edges, 59 | instead. Both allow edges to be selected based on vertex neighborhood and 60 | (optionally) an additional endpoint. 61 | } 62 | \details{ 63 | By default, \code{get.edges} returns all out-, in-, or out- and in-edges 64 | containing \code{v}. \code{get.edgeIDs} is identical, save in its return 65 | value, as it returns only the ids of the edges. Specifying a vertex in 66 | \code{alter} causes these edges to be further selected such that alter must 67 | also belong to the edge -- this can be used to extract edges between two 68 | particular vertices. Omission of missing edges is accomplished via 69 | \code{na.omit}. Note that for multiplex networks, multiple edges or edge 70 | ids can be returned. 71 | 72 | The function \code{get.dyads.eids} simplifies the process of looking up the 73 | edge ids associated with a set of 'dyads' (tail and head vertex ids) for 74 | edges. It only is intended for working with non-multiplex networks and will 75 | return a warning and \code{NA} value for any dyads that correspond to 76 | multiple edges. The value \code{numeric(0)} will be returned for any dyads 77 | that do not have a corresponding edge. 78 | } 79 | \examples{ 80 | 81 | #Create a network with three edges 82 | m<-matrix(0,3,3) 83 | m[1,2]<-1; m[2,3]<-1; m[3,1]<-1 84 | g<-network(m) 85 | 86 | get.edges(g,1,neighborhood="out") 87 | get.edgeIDs(g,1,neighborhood="in") 88 | 89 | } 90 | \references{ 91 | Butts, C. T. (2008). \dQuote{network: a Package for Managing 92 | Relational Data in R.} \emph{Journal of Statistical Software}, 24(2). 93 | \doi{10.18637/jss.v024.i02} 94 | } 95 | \seealso{ 96 | \code{\link{get.neighborhood}}, \code{\link{valid.eids}} 97 | } 98 | \author{ 99 | Carter T. Butts \email{buttsc@uci.edu} 100 | } 101 | \keyword{classes} 102 | \keyword{graphs} 103 | -------------------------------------------------------------------------------- /man/get.inducedSubgraph.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/access.R, R/operators.R 3 | \name{get.inducedSubgraph} 4 | \alias{get.inducedSubgraph} 5 | \alias{get.inducedSubgraph.network} 6 | \alias{\%s\%} 7 | \title{Retrieve Induced Subgraphs and Cuts} 8 | \usage{ 9 | get.inducedSubgraph(x, ...) 10 | 11 | \method{get.inducedSubgraph}{network}(x, v, alters = NULL, eid = NULL, ...) 12 | 13 | x \%s\% v 14 | } 15 | \arguments{ 16 | \item{x}{an object of class \code{network}.} 17 | 18 | \item{...}{additional arguments for methods.} 19 | 20 | \item{v}{a vector of vertex IDs, or, for \code{\%s\%}, optionally a list containing two disjoint vectors of vertex IDs (see below).} 21 | 22 | \item{alters}{optionally, a second vector of vertex IDs. Must be disjoint 23 | with \code{v}.} 24 | 25 | \item{eid}{optionally, a numeric vector of valid edge ids in \code{x} that 26 | should be retained (cannot be used with \code{v} or \code{alter})} 27 | } 28 | \value{ 29 | A \code{\link{network}} object containing the induced subgraph. 30 | } 31 | \description{ 32 | Given a set of vertex IDs, \code{get.inducedSubgraph} returns the subgraph 33 | induced by the specified vertices (i.e., the vertices and all associated 34 | edges). Optionally, passing a second set of alters returns the cut from the 35 | first to the second set (i.e., all edges passing between the sets), along 36 | with the associated endpoints. Alternatively, passing in a vector of edge 37 | ids will induce a subgraph containing the specified edges and their incident 38 | vertices. In all cases, the result is returned as a network object, with 39 | all attributes of the selected edges and/or vertices (and any network 40 | attributes) preserved. 41 | } 42 | \details{ 43 | For \code{get.inducedSubgraph}, \code{v} can be a vector of vertex IDs. If 44 | \code{alter=NULL}, the subgraph induced by these vertices is returned. 45 | Calling \code{\%s\%} with a single vector of vertices has an identical effect. 46 | 47 | Where \code{alters} is specified, it must be a vector of IDs disjoint with 48 | \code{v}. Where both are given, the edges spanning \code{v} and 49 | \code{alters} are returned, along with the vertices in question. 50 | (Technically, only the edges really constitute the \dQuote{cut,} but the 51 | vertices are included as well.) The same result can be obtained with the 52 | \code{\%s\%} operator by passing a two-element list on the right hand side; 53 | the first element is then interpreted as \code{v}, and the second as 54 | \code{alters}. 55 | 56 | When \code{eid} is specified, the \code{v} and \code{alters} argument will 57 | be ignored and the subgraph induced by the specified edges and their 58 | incident vertices will be returned. 59 | 60 | Any network, vertex, or edge attributes for the selected network elements 61 | are retained (although features such as vertex IDs and the network size will 62 | typically change). These are copies of the elements in the original 63 | network, which is not altered by this function. 64 | } 65 | \examples{ 66 | 67 | #Load the Drabek et al. EMON data 68 | data(emon) 69 | 70 | #For the Mt. St. Helens, EMON, several types of organizations are present: 71 | type<-emon$MtStHelens \%v\% "Sponsorship" 72 | 73 | #Plot interactions among the state organizations 74 | plot(emon$MtStHelens \%s\% which(type=="State"), displaylabels=TRUE) 75 | 76 | #Plot state/federal interactions 77 | plot(emon$MtStHelens \%s\% list(which(type=="State"), 78 | which(type=="Federal")), displaylabels=TRUE) 79 | 80 | #Plot state interactions with everyone else 81 | plot(emon$MtStHelens \%s\% list(which(type=="State"), 82 | which(type!="State")), displaylabels=TRUE) 83 | 84 | # plot only interactions with frequency of 2 85 | subG2<-get.inducedSubgraph(emon$MtStHelens, 86 | eid=which(emon$MtStHelens\%e\%'Frequency'==2)) 87 | plot(subG2,edge.label='Frequency') 88 | 89 | 90 | } 91 | \seealso{ 92 | \code{\link{network}}, \code{\link{network.extraction}} 93 | } 94 | \author{ 95 | Carter T. Butts \email{buttsc@uci.edu} 96 | } 97 | \keyword{graphs} 98 | \keyword{manip} 99 | -------------------------------------------------------------------------------- /man/get.neighborhood.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/access.R 3 | \name{get.neighborhood} 4 | \alias{get.neighborhood} 5 | \title{Obtain the Neighborhood of a Given Vertex} 6 | \usage{ 7 | get.neighborhood(x, v, type = c("out", "in", "combined"), na.omit = TRUE) 8 | } 9 | \arguments{ 10 | \item{x}{an object of class \code{network}} 11 | 12 | \item{v}{a vertex ID} 13 | 14 | \item{type}{the neighborhood to be computed} 15 | 16 | \item{na.omit}{logical; should missing edges be ignored when obtaining 17 | vertex neighborhoods?} 18 | } 19 | \value{ 20 | A vector containing the vertex IDs for the chosen neighborhood. 21 | } 22 | \description{ 23 | \code{get.neighborhood} returns the IDs of all vertices belonging to the in, 24 | out, or combined neighborhoods of \code{v} within network \code{x}. 25 | } 26 | \details{ 27 | Note that the combined neighborhood is the union of the in and out 28 | neighborhoods -- as such, no vertex will appear twice. 29 | } 30 | \examples{ 31 | 32 | #Create a network with three edges 33 | m<-matrix(0,3,3) 34 | m[1,2]<-1; m[2,3]<-1; m[3,1]<-1 35 | g<-network(m) 36 | 37 | #Examine the neighborhood of vertex 1 38 | get.neighborhood(g,1,"out") 39 | get.neighborhood(g,1,"in") 40 | get.neighborhood(g,1,"combined") 41 | 42 | } 43 | \references{ 44 | Butts, C. T. (2008). \dQuote{network: a Package for Managing 45 | Relational Data in R.} \emph{Journal of Statistical Software}, 24(2). 46 | \doi{10.18637/jss.v024.i02} 47 | 48 | Wasserman, S. and Faust, K. 1994. \emph{Social Network Analysis: Methods 49 | and Applications.} Cambridge: Cambridge University Press. 50 | } 51 | \seealso{ 52 | \code{\link{get.edges}}, \code{\link{is.adjacent}} 53 | } 54 | \author{ 55 | Carter T. Butts \email{buttsc@uci.edu} 56 | } 57 | \keyword{graphs} 58 | -------------------------------------------------------------------------------- /man/has.edges.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/misc.R 3 | \name{has.edges} 4 | \alias{has.edges} 5 | \alias{is.isolate} 6 | \title{Determine if specified vertices of a network have any edges (are not 7 | isolates)} 8 | \usage{ 9 | has.edges(net, v = seq_len(network.size(net))) 10 | } 11 | \arguments{ 12 | \item{net}{a \code{\link{network}} object to be queried} 13 | 14 | \item{v}{integer vector of vertex ids to check} 15 | } 16 | \value{ 17 | returns a logical vector with the same length as v, with TRUE if the 18 | vertex is involved in any edges, FALSE if it is an isolate. 19 | } 20 | \description{ 21 | Returns a logical value for each specified vertex, indicating if it has any 22 | incident (in or out) edges. Checks all vertices by default 23 | } 24 | \examples{ 25 | 26 | test<-network.initialize(5) 27 | test[1,2]<-1 28 | has.edges(test) 29 | has.edges(test,v=5) 30 | 31 | } 32 | \author{ 33 | skyebend 34 | } 35 | -------------------------------------------------------------------------------- /man/is.adjacent.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/access.R 3 | \name{is.adjacent} 4 | \alias{is.adjacent} 5 | \title{Determine Whether Two Vertices Are Adjacent} 6 | \usage{ 7 | is.adjacent(x, vi, vj, na.omit = FALSE) 8 | } 9 | \arguments{ 10 | \item{x}{an object of class \code{network}} 11 | 12 | \item{vi}{a vertex ID} 13 | 14 | \item{vj}{a second vertex ID} 15 | 16 | \item{na.omit}{logical; should missing edges be ignored when assessing 17 | adjacency?} 18 | } 19 | \value{ 20 | A logical, giving the status of the (i,j) edge 21 | } 22 | \description{ 23 | \code{is.adjacent} returns \code{TRUE} iff \code{vi} is adjacent to 24 | \code{vj} in \code{x}. Missing edges may be omitted or not, as per 25 | \code{na.omit}. 26 | } 27 | \details{ 28 | Vertex \eqn{v} is said to be adjacent to vertex \eqn{v'} within directed 29 | network \eqn{G} iff there exists some edge whose tail set contains \eqn{v} 30 | and whose head set contains \eqn{v'}. In the undirected case, head and tail 31 | sets are exchangeable, and thus \eqn{v} is adjacent to \eqn{v'} if there 32 | exists an edge such that \eqn{v} belongs to one endpoint set and \eqn{v'} 33 | belongs to the other. (In dyadic graphs, these sets are of cardinality 1, 34 | but this may not be the case where hyperedges are admitted.) 35 | 36 | If an edge which would make \eqn{v} and \eqn{v'} adjacent is marked as 37 | missing (via its \code{na} attribute), then the behavior of 38 | \code{is.adjacent} depends upon \code{na.omit}. If \code{na.omit==FALSE} 39 | (the default), then the return value is considered to be \code{NA} unless 40 | there is also \emph{another} edge from \eqn{v} to \eqn{v'} which is 41 | \emph{not} missing (in which case the two are clearly adjacent). If 42 | \code{na.omit==TRUE}, on the other hand the missing edge is simply 43 | disregarded in assessing adjacency (i.e., it effectively treated as not 44 | present). It is important not to confuse \dQuote{not present} with 45 | \dQuote{missing} in this context: the former indicates that the edge in 46 | question does not belong to the network, while the latter indicates that the 47 | state of the corresponding edge is regarded as unknown. By default, all 48 | edge states are assumed \dQuote{known} unless otherwise indicated (by 49 | setting the edge's \code{na} attribute to \code{TRUE}; see 50 | \code{\link{attribute.methods}}). 51 | 52 | Adjacency can also be determined via the extraction/replacement operators. 53 | See the associated man page for details. 54 | } 55 | \note{ 56 | Prior to version 1.4, \code{na.omit} was set to \code{TRUE} by 57 | default. 58 | } 59 | \examples{ 60 | 61 | #Create a very simple graph 62 | g<-network.initialize(3) 63 | add.edge(g,1,2) 64 | is.adjacent(g,1,2) #TRUE 65 | is.adjacent(g,2,1) #FALSE 66 | g[1,2]==1 #TRUE 67 | g[2,1]==1 #FALSE 68 | 69 | } 70 | \references{ 71 | Butts, C. T. (2008). \dQuote{network: a Package for Managing 72 | Relational Data in R.} \emph{Journal of Statistical Software}, 24(2). 73 | \doi{10.18637/jss.v024.i02} 74 | 75 | Wasserman, S. and Faust, K. 1994. \emph{Social Network Analysis: Methods 76 | and Applications}. Cambridge: Cambridge University Press. 77 | } 78 | \seealso{ 79 | \code{\link{get.neighborhood}}, \code{\link{network.extraction}}, 80 | \code{\link{attribute.methods}} 81 | } 82 | \author{ 83 | Carter T. Butts \email{buttsc@uci.edu} 84 | } 85 | \keyword{graphs} 86 | -------------------------------------------------------------------------------- /man/mixingmatrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/misc.R 3 | \name{mixingmatrix} 4 | \alias{mixingmatrix} 5 | \alias{mixingmatrix.network} 6 | \alias{[[.mixingmatrix} 7 | \alias{$.mixingmatrix} 8 | \alias{is.directed.mixingmatrix} 9 | \alias{is.bipartite.mixingmatrix} 10 | \alias{print.mixingmatrix} 11 | \title{Mixing matrix} 12 | \usage{ 13 | mixingmatrix(object, ...) 14 | 15 | \method{mixingmatrix}{network}(object, attrname, useNA = "ifany", expand.bipartite = FALSE, ...) 16 | 17 | \method{[[}{mixingmatrix}(x, ...) 18 | 19 | \method{$}{mixingmatrix}(x, name) 20 | 21 | \method{is.directed}{mixingmatrix}(x, ...) 22 | 23 | \method{is.bipartite}{mixingmatrix}(x, ...) 24 | 25 | \method{print}{mixingmatrix}(x, ...) 26 | } 27 | \arguments{ 28 | \item{object}{a network or some other data structure for which a mixing 29 | matrix is meaningful.} 30 | 31 | \item{...}{arguments passed to \code{\link{table}}.} 32 | 33 | \item{attrname}{a vertex attribute name.} 34 | 35 | \item{useNA}{one of "ifany", "no" or "always". Argument passed to 36 | \code{\link{table}}. By default (\code{useNA = "ifany"}) if there are any 37 | \code{NA}s on the attribute corresponding row \emph{and} column will be 38 | contained in the result. See Details.} 39 | 40 | \item{expand.bipartite}{logical; if \code{object} is bipartite, should we return 41 | the \emph{square} mixing matrix representing every level of \code{attrname} against 42 | every other level, or a \emph{rectangular} matrix considering only levels 43 | present in each bipartition?} 44 | 45 | \item{x}{mixingmatrix object} 46 | 47 | \item{name}{name of the element to extract, one of "matrix" or "type"} 48 | } 49 | \value{ 50 | Function \code{mixingmatrix()} returns an object of class \code{mixingmatrix} 51 | extending \code{table} with a cross-tabulation of edges in the \code{object} 52 | according to the values of attribute \code{attrname} for the two incident 53 | vertices. If \code{object} is a \emph{directed} network rows correspond to the "tie 54 | sender" and columns to the "tie receiver". If \code{object} is an \emph{undirected} 55 | network there is no such distinction and the matrix is symmetrized. In both 56 | cases the matrix is square and all the observed values of the attribute 57 | \code{attrname} are represented in rows and columns. If \code{object} is a 58 | \emph{bipartite} network and \code{expand.bipartite} is \code{FALSE} the resulting matrix 59 | does not have to be square as only the actually observed values of the 60 | attribute are shown for each partition, if \code{expand.bipartite} is \code{TRUE} the 61 | matrix will be square. 62 | 63 | Functions \code{is.directed()} and \code{is.bipartite()} return \code{TRUE} or 64 | \code{FALSE}. The values will be identical for the input network \code{object}. 65 | } 66 | \description{ 67 | Return the mixing matrix for a network, on a given attribute. 68 | } 69 | \details{ 70 | Handling of missing values on the attribute \code{attrname} almost 71 | follows similar logic to \code{\link{table}}. If there are \code{NA}s on 72 | the attribute and \code{useNA="ifany"} (default) the result will contain 73 | both row and column for the missing values to ensure the resulting matrix 74 | is square (essentially calling \code{\link{table}} with 75 | \code{useNA="always"}). Also for that reason passing \code{exclude} 76 | parameter with \code{NULL}, \code{NA} or \code{NaN} is ignored with a 77 | warning as it may break the symmetry. 78 | } 79 | \note{ 80 | The \code{$} and \code{[[} methods are included only for backward-compatiblity 81 | reason and will become defunct in future releases of the package. 82 | } 83 | \examples{ 84 | # Interaction ties between Lake Pomona SAR organizations by sponsorship type 85 | # of tie sender and receiver (data from Drabek et al. 1981) 86 | data(emon) 87 | mixingmatrix(emon$LakePomona, "Sponsorship") 88 | } 89 | -------------------------------------------------------------------------------- /man/network-internal.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/misc.R, R/operators.R 3 | \name{network-internal} 4 | \alias{network-internal} 5 | \alias{is.discrete.numeric} 6 | \alias{is.discrete.character} 7 | \alias{is.discrete} 8 | \alias{networkOperatorSetup} 9 | \title{Internal Network Package Functions} 10 | \usage{ 11 | is.discrete.numeric(x) 12 | 13 | is.discrete.character(x) 14 | 15 | is.discrete(x) 16 | 17 | networkOperatorSetup(x, y = NULL) 18 | } 19 | \arguments{ 20 | \item{x}{an object to be designated either discrete or continuous, or a 21 | network.} 22 | 23 | \item{y}{a network or something coercible to one.} 24 | } 25 | \description{ 26 | Internal network functions. 27 | } 28 | \details{ 29 | Most of these are not to be called by the user. 30 | } 31 | \seealso{ 32 | network 33 | } 34 | \keyword{internal} 35 | -------------------------------------------------------------------------------- /man/network-operators.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/operators.R 3 | \name{network.operators} 4 | \alias{network.operators} 5 | \alias{+.network} 6 | \alias{\%c\%} 7 | \alias{-.network} 8 | \alias{*.network} 9 | \alias{!.network} 10 | \alias{|.network} 11 | \alias{&.network} 12 | \alias{\%c\%.network} 13 | \title{Network Operators} 14 | \usage{ 15 | \method{+}{network}(e1, e2) 16 | 17 | \method{-}{network}(e1, e2) 18 | 19 | \method{*}{network}(e1, e2) 20 | 21 | \method{!}{network}(e1) 22 | 23 | \method{|}{network}(e1, e2) 24 | 25 | \method{&}{network}(e1, e2) 26 | 27 | \method{\%c\%}{network}(e1, e2) 28 | } 29 | \arguments{ 30 | \item{e1}{an object of class \code{network}.} 31 | 32 | \item{e2}{another \code{network}.} 33 | } 34 | \value{ 35 | The resulting network. 36 | } 37 | \description{ 38 | These operators allow for algebraic manipulation of relational structures. 39 | } 40 | \details{ 41 | In general, the binary network operators function by producing a new network 42 | object whose edge structure is based on that of the input networks. The 43 | properties of the new structure depend upon the inputs as follows: \itemize{ 44 | \item The size of the new network is equal to the size of the input networks 45 | (for all operators save \code{\%c\%}), which must themselves be of equal size. 46 | Likewise, the \code{bipartite} attributes of the inputs must match, and this 47 | is preserved in the output. \item If either input network allows loops, 48 | multiplex edges, or hyperedges, the output acquires this property. (If both 49 | input networks do not allow these features, then the features are disallowed 50 | in the output network.) \item If either input network is directed, the 51 | output is directed; if exactly one input network is directed, the undirected 52 | input is treated as if it were a directed network in which all edges are 53 | reciprocated. \item Supplemental attributes (including vertex names, but 54 | not edgwise missingness) are not transferred to the output. } The unary 55 | operator acts per the above, but with a single input. Thus, the output 56 | network has the same properties as the input, with the exception of 57 | supplemental attributes. 58 | 59 | The behavior of the composition operator, \code{\%c\%}, is somewhat more 60 | complex than the others. In particular, it will return a bipartite network 61 | whenever either input network is bipartite \emph{or} the vertex names of the 62 | two input networks do not match (or are missing). If both inputs are 63 | non-bipartite and have identical vertex names, the return value will have 64 | the same structure (but with loops). This behavior corresponds to the 65 | interpretation of the composition operator as counting walks on labeled sets 66 | of vertices. 67 | 68 | Hypergraphs are not yet supported by these routines, but ultimately will be 69 | (as suggested by the above). 70 | 71 | The specific operations carried out by these operators are generally 72 | self-explanatory in the non-multiplex case, but semantics in the latter 73 | circumstance bear elaboration. The following summarizes the behavior of 74 | each operator: 75 | \describe{ 76 | \item{\code{+}}{An \eqn{(i,j)} edge is created in 77 | the return graph for every \eqn{(i,j)} edge in each of the input graphs.} 78 | \item{\code{-}}{An \eqn{(i,j)} edge is created in the return graph for 79 | every \eqn{(i,j)} edge in the first input that is not matched by an 80 | \eqn{(i,j)} edge in the second input; if the second input has more 81 | \eqn{(i,j)} edges than the first, no \eqn{(i,j)} edges are created in the 82 | return graph.} 83 | \item{\code{*}}{An \eqn{(i,j)} edge is created for every 84 | pairing of \eqn{(i,j)} edges in the respective input graphs.} 85 | \item{\code{\%c\%}}{An \eqn{(i,j)} edge is created in the return graph for 86 | every edge pair \eqn{(i,k),(k,j)} with the first edge in the first input and 87 | the second edge in the second input.} 88 | \item{\code{!}}{An \eqn{(i,j)} edge 89 | is created in the return graph for every \eqn{(i,j)} in the input not having 90 | an edge.} 91 | \item{\code{|}}{An \eqn{(i,j)} edge is created in the return 92 | graph if either input contains an \eqn{(i,j)} edge.} 93 | \item{\code{&}}{An 94 | \eqn{(i,j)} edge is created in the return graph if both inputs contain an 95 | \eqn{(i,j)} edge.} 96 | } 97 | Semantics for missing-edge cases follow from the above, 98 | under the interpretation that edges with \code{na==TRUE} are viewed as 99 | having an unknown state. Thus, for instance, \code{x*y} with \code{x} 100 | having 2 \eqn{(i,j)} non-missing and 1 missing edge and \code{y} having 3 101 | respective non-missing and 2 missing edges will yield an output network with 102 | 6 non-missing and 9 missing \eqn{(i,j)} edges. 103 | } 104 | \note{ 105 | Currently, there is a naming conflict between the composition operator 106 | and the \code{\%c\%} operator in the \code{\link[sna]{sna}} package. This 107 | will be resolved in future releases; for the time being, one can determine 108 | which version of \code{\%c\%} is in use by varying which package is loaded 109 | first. 110 | } 111 | \examples{ 112 | 113 | #Create an in-star 114 | m<-matrix(0,6,6) 115 | m[2:6,1]<-1 116 | g<-network(m) 117 | plot(g) 118 | 119 | #Compose g with its transpose 120 | gcgt<-g \%c\% (network(t(m))) 121 | plot(gcgt) 122 | gcgt 123 | 124 | #Show the complement of g 125 | !g 126 | 127 | #Perform various arithmatic and logical operations 128 | (g+gcgt)[,] == (g|gcgt)[,] #All TRUE 129 | (g-gcgt)[,] == (g&(!(gcgt)))[,] 130 | (g*gcgt)[,] == (g&gcgt)[,] 131 | } 132 | \references{ 133 | Butts, C. T. (2008). \dQuote{network: a Package for Managing 134 | Relational Data in R.} \emph{Journal of Statistical Software}, 24(2). 135 | \doi{10.18637/jss.v024.i02} 136 | 137 | Wasserman, S. and Faust, K. (1994). \emph{Social Network Analysis: Methods 138 | and Applications.} Cambridge: University of Cambridge Press. 139 | } 140 | \seealso{ 141 | \code{\link{network.extraction}} 142 | } 143 | \author{ 144 | Carter T. Butts \email{buttsc@uci.edu} 145 | } 146 | \keyword{graphs} 147 | \keyword{math} 148 | -------------------------------------------------------------------------------- /man/network-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/network-package.R 3 | \docType{package} 4 | \name{network-package} 5 | \alias{network-package} 6 | \title{Classes for Relational Data} 7 | \description{ 8 | Tools to create and modify network objects. The network class can represent 9 | a range of relational data types, and supports arbitrary vertex/edge/graph 10 | attributes. 11 | } 12 | \details{ 13 | The \code{network} package provides tools for creation, access, and 14 | modification of \code{network} class objects. These objects allow for the 15 | representation of more complex structures than can be readily handled by 16 | other means (e.g., adjacency matrices), and are substantially more efficient 17 | in handling large, sparse networks. While the full capabilities of the 18 | \code{network} class can only be exploited by means of the various custom 19 | interface methods (see below), many simple tasks are streamlined through the 20 | use of operator overloading; in particular, network objects can often be 21 | treated as if they were adjacency matrices (a representation which will be 22 | familiar to users of the \code{sna} package). \code{network} objects are 23 | compatible with the \code{sna} package, and are required for many packages 24 | in the \code{statnet} bundle. 25 | 26 | Basic information on the creation of \code{network} objects can be found by 27 | typing \code{help(network)}. To learn about setting, modifying, or deleting 28 | network, vertex, or edge attributes, see \code{help(attribute.methods)}. 29 | For information on custom network operators, type 30 | \code{help(network.operators)}; information on overloaded operators can be 31 | found via \code{help(network.extraction)}. Additional help topics are 32 | listed below. 33 | 34 | \tabular{ll}{ 35 | Package: \tab network\cr 36 | Version: \tab 1.14\cr 37 | Date: \tab May 7, 2016\cr 38 | Depends: \tab R (>= 2.10), utils\cr 39 | Suggests: \tab sna, statnet.common (>= 3.1-0)\cr 40 | License: \tab GPL (>=2)\cr 41 | } 42 | 43 | Index of documentation pages: 44 | \preformatted{ 45 | add.edges Add Edges to a Network Object 46 | add.vertices Add Vertices to an Existing Network 47 | as.matrix.network Coerce a Network Object to Matrix Form 48 | as.network.matrix Coercion from Matrices to Network Objects 49 | as.sociomatrix Coerce One or More Networks to Sociomatrix Form 50 | attribute.methods Attribute Interface Methods for the Network 51 | Class 52 | deletion.methods Remove Elements from a Network Object 53 | edgeset.constructors Edgeset Constructors for Network Objects 54 | emon Interorganizational Search and Rescue Networks 55 | (Drabek et al.) 56 | flo Florentine Wedding Data (Padgett) 57 | get.edges Retrieve Edges or Edge IDs Associated with a 58 | Given Vertex 59 | get.inducedSubgraph Retrieve Induced Subgraphs and Cuts 60 | get.neighborhood Obtain the Neighborhood of a Given Vertex 61 | is.adjacent Determine Whether Two Vertices Are Adjacent 62 | loading.attributes Examples of how to load vertex and edge 63 | attributes into networks 64 | missing.edges Identifying and Counting Missing Edges in a 65 | Network Object 66 | network Network Objects 67 | network.arrow Add Arrows or Segments to a Plot 68 | network.density Compute the Density of a Network 69 | network.dyadcount Return the Number of (Possibly Directed) Dyads 70 | in a Network Object 71 | network.edgecount Return the Number of Edges in a Network Object 72 | network.edgelabel Plots a label corresponding to an edge in a 73 | network plot. 74 | network.extraction Extraction and Replacement Operators for 75 | Network Objects 76 | network.indicators Indicator Functions for Network Properties 77 | network.initialize Initialize a Network Class Object 78 | network.layout Vertex Layout Functions for plot.network 79 | network.loop Add Loops to a Plot 80 | network.operators Network Operators 81 | network-package Classes for Relational Data 82 | network.size Return the Size of a Network 83 | network.vertex Add Vertices to a Plot 84 | permute.vertexIDs Permute (Relabel) the Vertices Within a Network 85 | plotArgs.network Expand and transform attributes of networks to 86 | values appropriate for aguments to plot.network 87 | plot.network.default Two-Dimensional Visualization for Network 88 | Objects 89 | prod.network Combine Networks by Edge Value Multiplication 90 | read.paj Read a Pajek Project or Network File and 91 | Convert to an R 'Network' Object 92 | sum.network Combine Networks by Edge Value Addition 93 | valid.eids Get the valid edge which are valid in a network 94 | which.matrix.type Heuristic Determination of Matrix Types for 95 | Network Storage 96 | } 97 | } 98 | \seealso{ 99 | Useful links: 100 | \itemize{ 101 | \item \url{https://statnet.org/} 102 | } 103 | 104 | } 105 | \author{ 106 | Carter T. Butts \href{mailto:buttsc@uci.edu}{buttsc@uci.edu}, with help from Mark S. Handcock 107 | \href{mailto:handcock@stat.ucla.edu}{handcock@stat.ucla.edu}, David Hunter \href{mailto:dhunter@stat.psu.edu}{dhunter@stat.psu.edu}, Martina 108 | Morris \href{mailto:morrism@u.washington.edu}{morrism@u.washington.edu}, Skye Bender-deMoll 109 | \href{mailto:skyebend@u.washington.edu}{skyebend@u.washington.edu}, and Jeffrey Horner 110 | \href{mailto:jeffrey.horner@gmail.com}{jeffrey.horner@gmail.com}. 111 | 112 | Maintainer: Carter T. Butts \href{mailto:buttsc@uci.edu}{buttsc@uci.edu} 113 | } 114 | \keyword{package} 115 | -------------------------------------------------------------------------------- /man/network.arrow.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot.R 3 | \name{network.arrow} 4 | \alias{network.arrow} 5 | \title{Add Arrows or Segments to a Plot} 6 | \usage{ 7 | network.arrow( 8 | x0, 9 | y0, 10 | x1, 11 | y1, 12 | length = 0.1, 13 | angle = 20, 14 | width = 0.01, 15 | col = 1, 16 | border = 1, 17 | lty = 1, 18 | offset.head = 0, 19 | offset.tail = 0, 20 | arrowhead = TRUE, 21 | curve = 0, 22 | edge.steps = 50, 23 | ... 24 | ) 25 | } 26 | \arguments{ 27 | \item{x0}{A vector of x coordinates for points of origin} 28 | 29 | \item{y0}{A vector of y coordinates for points of origin} 30 | 31 | \item{x1}{A vector of x coordinates for destination points} 32 | 33 | \item{y1}{A vector of y coordinates for destination points} 34 | 35 | \item{length}{Arrowhead length, in current plotting units} 36 | 37 | \item{angle}{Arrowhead angle (in degrees)} 38 | 39 | \item{width}{Width for arrow body, in current plotting units (can be a 40 | vector)} 41 | 42 | \item{col}{Arrow body color (can be a vector)} 43 | 44 | \item{border}{Arrow border color (can be a vector)} 45 | 46 | \item{lty}{Arrow border line type (can be a vector)} 47 | 48 | \item{offset.head}{Offset for destination point (can be a vector)} 49 | 50 | \item{offset.tail}{Offset for origin point (can be a vector)} 51 | 52 | \item{arrowhead}{Boolean; should arrowheads be used? (Can be a vector))} 53 | 54 | \item{curve}{Degree of edge curvature (if any), in current plotting units 55 | (can be a vector)} 56 | 57 | \item{edge.steps}{For curved edges, the number of steps to use in 58 | approximating the curve (can be a vector)} 59 | 60 | \item{\dots}{Additional arguments to \code{\link{polygon}}} 61 | } 62 | \value{ 63 | None. 64 | } 65 | \description{ 66 | \code{network.arrow} draws a segment or arrow between two pairs of points; 67 | unlike \code{\link{arrows}} or \code{\link{segments}}, the new plot element 68 | is drawn as a polygon. 69 | } 70 | \details{ 71 | \code{network.arrow} provides a useful extension of \code{\link{segments}} 72 | and \code{\link{arrows}} when fine control is needed over the resulting 73 | display. (The results also look better.) Note that edge curvature is 74 | quadratic, with \code{curve} providing the maximum horizontal deviation of 75 | the edge (left-handed). Head/tail offsets are used to adjust the end/start 76 | points of an edge, relative to the baseline coordinates; these are useful 77 | for functions like \code{\link{plot.network}}, which need to draw edges 78 | incident to vertices of varying radii. 79 | } 80 | \note{ 81 | \code{network.arrow} is a direct adaptation of 82 | \code{\link[sna]{gplot.arrow}} from the \code{sna} package. 83 | } 84 | \examples{ 85 | 86 | #Plot two points 87 | plot(1:2,1:2) 88 | 89 | #Add an edge 90 | network.arrow(1,1,2,2,width=0.01,col="red",border="black") 91 | 92 | } 93 | \references{ 94 | Butts, C. T. (2008). \dQuote{network: a Package for Managing 95 | Relational Data in R.} \emph{Journal of Statistical Software}, 24(2). 96 | \doi{10.18637/jss.v024.i02} 97 | } 98 | \seealso{ 99 | \code{\link{plot.network}}, \code{\link{network.loop}}, 100 | \code{\link{polygon}} 101 | } 102 | \author{ 103 | Carter T. Butts \email{buttsc@uci.edu} 104 | } 105 | \keyword{aplot} 106 | \keyword{graphs} 107 | -------------------------------------------------------------------------------- /man/network.density.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/misc.R 3 | \name{network.density} 4 | \alias{network.density} 5 | \title{Compute the Density of a Network} 6 | \usage{ 7 | network.density(x, na.omit = TRUE, discount.bipartite = FALSE) 8 | } 9 | \arguments{ 10 | \item{x}{an object of class \code{network}} 11 | 12 | \item{na.omit}{logical; omit missing edges from extant edges when assessing 13 | density?} 14 | 15 | \item{discount.bipartite}{logical; if \code{x} is bipartite, should 16 | \dQuote{forbidden} edges be excluded from the count of potential edges?} 17 | } 18 | \value{ 19 | The network density. 20 | } 21 | \description{ 22 | \code{network.density} computes the density of its argument. 23 | } 24 | \details{ 25 | The density of a network is defined as the ratio of extant edges to 26 | potential edges. We do not currently consider edge values; missing edges are 27 | omitted from extent (but not potential) edge count when 28 | \code{na.omit==TRUE}. 29 | } 30 | \section{Warning }{ 31 | \code{network.density} relies on network attributes (see 32 | \link{network.indicators}) to determine the properties of the underlying 33 | network object. If these are set incorrectly (e.g., multiple edges in a 34 | non-multiplex network, network coded with directed edges but set to 35 | \dQuote{undirected}, etc.), surprising results may ensue. 36 | } 37 | 38 | \examples{ 39 | 40 | #Create an arbitrary adjacency matrix 41 | m<-matrix(rbinom(25,1,0.5),5,5) 42 | diag(m)<-0 43 | 44 | g<-network.initialize(5) #Initialize the network 45 | network.density(g) #Calculate the density 46 | 47 | } 48 | \references{ 49 | Butts, C. T. (2008). \dQuote{network: a Package for Managing 50 | Relational Data in R.} \emph{Journal of Statistical Software}, 24(2). 51 | \doi{10.18637/jss.v024.i02} 52 | 53 | Wasserman, S. and Faust, K. (1994). \emph{Social Network Analysis: Methods 54 | and Applications.} Cambridge: Cambridge University Press. 55 | } 56 | \seealso{ 57 | \code{\link{network.edgecount}}, \code{\link{network.size}} 58 | } 59 | \author{ 60 | Carter T. Butts \email{buttsc@uci.edu} 61 | } 62 | \keyword{graphs} 63 | -------------------------------------------------------------------------------- /man/network.dyadcount.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/access.R 3 | \name{network.dyadcount} 4 | \alias{network.dyadcount} 5 | \alias{network.dyadcount.network} 6 | \title{Return the Number of (Possibly Directed) Dyads in a Network Object} 7 | \usage{ 8 | \method{network.dyadcount}{network}(x, na.omit = TRUE, ...) 9 | } 10 | \arguments{ 11 | \item{x}{an object of class \code{network}} 12 | 13 | \item{na.omit}{logical; omit edges with \code{na==TRUE} from the count?} 14 | 15 | \item{\dots}{possible additional arguments, used by other implementations} 16 | } 17 | \value{ 18 | The number of dyads in the network 19 | } 20 | \description{ 21 | \code{network.dyadcount} returns the number of possible dyads within a 22 | \code{network}, removing those flagged as missing if desired. If the 23 | network is directed, directed dyads are counted accordingly. 24 | } 25 | \details{ 26 | The return value \code{network.dyadcount} is equal to the number of dyads, 27 | minus the number of \code{NULL} edges (and missing edges, if 28 | \code{na.omit==TRUE}). If \code{x} is directed, the number of directed 29 | dyads is returned. If the network allows loops, the number of possible 30 | entries on the diagnonal is added. Allthough the function does not give an 31 | error on multiplex networks or hypergraphs, the results probably don't make 32 | sense. 33 | } 34 | \examples{ 35 | 36 | #Create a directed network with three edges 37 | m<-matrix(0,3,3) 38 | m[1,2]<-1; m[2,3]<-1; m[3,1]<-1 39 | g<-network(m) 40 | network.dyadcount(g)==6 #Verify the directed dyad count 41 | g<-network(m|t(m),directed=FALSE) 42 | network.dyadcount(g)==3 #nC2 in undirected case 43 | 44 | } 45 | \references{ 46 | Butts, C. T. (2008). \dQuote{network: a Package for Managing 47 | Relational Data in R.} \emph{Journal of Statistical Software}, 24(2). 48 | \doi{10.18637/jss.v024.i02} 49 | } 50 | \seealso{ 51 | \code{\link{get.network.attribute}}, 52 | \code{\link{network.edgecount}}, \code{\link{is.directed}} 53 | } 54 | \author{ 55 | Mark S. Handcock \email{handcock@stat.washington.edu}, skyebend 56 | } 57 | \keyword{classes} 58 | \keyword{graphs} 59 | -------------------------------------------------------------------------------- /man/network.edgecount.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/access.R 3 | \name{network.edgecount} 4 | \alias{network.edgecount} 5 | \alias{network.edgecount.network} 6 | \title{Return the Number of Edges in a Network Object} 7 | \usage{ 8 | \method{network.edgecount}{network}(x, na.omit = TRUE, ...) 9 | } 10 | \arguments{ 11 | \item{x}{an object of class \code{network}} 12 | 13 | \item{na.omit}{logical; omit edges with \code{na==TRUE} from the count?} 14 | 15 | \item{\dots}{additional arguments, used by extending functio} 16 | } 17 | \value{ 18 | The number of edges 19 | } 20 | \description{ 21 | \code{network.edgecount} returns the number of edges within a 22 | \code{network}, removing those flagged as missing if desired. 23 | } 24 | \details{ 25 | The return value is the number of distinct edges within the network object, 26 | including multiplex edges as appropriate. (So if there are 3 edges from 27 | vertex i to vertex j, each contributes to the total edge count.) 28 | 29 | The return value \code{network.edgecount} is in the present implementation 30 | related to the (required) \code{mnext} network attribute. \code{mnext} is 31 | an internal legacy attribute that currently indicates the index number of 32 | the next edge to be added to a network object. (Do not modify it unless you 33 | enjoy unfortunate surprises.) The number of edges returned by 34 | \code{network.edgecount} is equal to \code{x\%n\%"mnext"-1}, minus the number 35 | of \code{NULL} edges (and missing edges, if \code{na.omit==TRUE}). Note 36 | that \code{g\%n\%"mnext"-1} cannot, by itself, be counted upon to be an 37 | accurate count of the number of edges! As \code{mnext} is not part of the 38 | API (and is not guaranteed to remain), users and developers are urged to use 39 | \code{network.edgecount} instead. 40 | } 41 | \section{Warning }{ 42 | \code{network.edgecount} uses the real state of the 43 | network object to count edges, not the state it hypothetically should have. 44 | Thus, if you add extra edges to a non-multiplex network, directed edges to 45 | an undirected network, etc., the actual number of edges in the object will 46 | be returned (and not the number you would expect if you relied only on the 47 | putative number of possible edges as reflected by the 48 | \link{network.indicators}). Don't create \code{network} objects with 49 | contradictory attributes unless you know what you are doing. 50 | } 51 | 52 | \examples{ 53 | 54 | #Create a network with three edges 55 | m<-matrix(0,3,3) 56 | m[1,2]<-1; m[2,3]<-1; m[3,1]<-1 57 | g<-network(m) 58 | network.edgecount(g)==3 #Verify the edgecount 59 | 60 | } 61 | \references{ 62 | Butts, C. T. (2008). \dQuote{network: a Package for Managing 63 | Relational Data in R.} \emph{Journal of Statistical Software}, 24(2). 64 | \doi{10.18637/jss.v024.i02} 65 | } 66 | \seealso{ 67 | \code{\link{get.network.attribute}} 68 | } 69 | \author{ 70 | Carter T. Butts \email{buttsc@uci.edu} 71 | } 72 | \keyword{classes} 73 | \keyword{graphs} 74 | -------------------------------------------------------------------------------- /man/network.edgelabel.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot.R 3 | \name{network.edgelabel} 4 | \alias{network.edgelabel} 5 | \title{Plots a label corresponding to an edge in a network plot.} 6 | \usage{ 7 | network.edgelabel( 8 | px0, 9 | py0, 10 | px1, 11 | py1, 12 | label, 13 | directed, 14 | loops = FALSE, 15 | cex, 16 | curve = 0, 17 | ... 18 | ) 19 | } 20 | \arguments{ 21 | \item{px0}{vector of x coordinates of tail vertex of the edge} 22 | 23 | \item{py0}{vector of y coordinates of tail vertex of the edge} 24 | 25 | \item{px1}{vector of x coordinates of head vertex of the edge} 26 | 27 | \item{py1}{vector of y coordinate of head vertex of the edge} 28 | 29 | \item{label}{vector strings giving labels to be drawn for edge edge} 30 | 31 | \item{directed}{logical: is the underlying network directed? If FALSE, 32 | labels will be drawn in the middle of the line segment, otherwise in the 33 | first 3rd so that the labels for edges pointing in the opposite direction 34 | will not overlap.} 35 | 36 | \item{loops}{logical: if true, assuming the labels to be drawn belong to 37 | loop-type edges and render appropriately} 38 | 39 | \item{cex}{numeric vector giving the text expansion factor for each label} 40 | 41 | \item{curve}{numeric vector controling the extent of edge curvature (0 = 42 | straight line edges)} 43 | 44 | \item{\dots}{additional arguments to be passed to \code{\link{text}}} 45 | } 46 | \value{ 47 | no value is returned but text will be rendered on the active plot 48 | } 49 | \description{ 50 | Draws a text labels on (or adjacent to) the line segments connecting 51 | vertices on a network plot. 52 | } 53 | \details{ 54 | Called internally by \code{\link{plot.network}} when \code{edge.label} 55 | parameter is used. For directed, non-curved edges, the labels are shifted 56 | towards the tail of the edge. Labels for curved edges are not shifted 57 | because opposite-direction edges curve the opposite way. Makes a crude 58 | attempt to shift labels to either side of line, and to draw the edge labels 59 | for self-loops near the vertex. No attempt is made to avoid overlap between 60 | vertex and edge labels. 61 | } 62 | \author{ 63 | skyebend 64 | } 65 | -------------------------------------------------------------------------------- /man/network.extraction.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/operators.R 3 | \name{network.extraction} 4 | \alias{network.extraction} 5 | \alias{[.network} 6 | \alias{[<-.network} 7 | \alias{\%e\%} 8 | \alias{\%e\%<-} 9 | \alias{\%eattr\%} 10 | \alias{\%eattr\%<-} 11 | \alias{\%n\%} 12 | \alias{\%n\%<-} 13 | \alias{\%nattr\%} 14 | \alias{\%nattr\%<-} 15 | \alias{\%v\%} 16 | \alias{\%v\%<-} 17 | \alias{\%vattr\%} 18 | \alias{\%vattr\%<-} 19 | \title{Extraction and Replacement Operators for Network Objects} 20 | \usage{ 21 | \method{[}{network}(x, i, j, na.omit = FALSE) 22 | 23 | \method{[}{network}(x, i, j, names.eval = NULL, add.edges = FALSE) <- value 24 | 25 | x \%e\% attrname 26 | 27 | x \%e\% attrname <- value 28 | 29 | x \%eattr\% attrname 30 | 31 | x \%eattr\% attrname <- value 32 | 33 | x \%n\% attrname 34 | 35 | x \%n\% attrname <- value 36 | 37 | x \%nattr\% attrname 38 | 39 | x \%nattr\% attrname <- value 40 | 41 | x \%v\% attrname 42 | 43 | x \%v\% attrname <- value 44 | 45 | x \%vattr\% attrname 46 | 47 | x \%vattr\% attrname <- value 48 | } 49 | \arguments{ 50 | \item{x}{an object of class \code{network}.} 51 | 52 | \item{i, j}{indices of the vertices with respect to which adjacency is to be 53 | tested. Empty values indicate that all vertices should be employed (see 54 | below).} 55 | 56 | \item{na.omit}{logical; should missing edges be omitted (treated as 57 | no-adjacency), or should \code{NA}s be returned? (Default: return \code{NA} 58 | on missing.)} 59 | 60 | \item{names.eval}{optionally, the name of an edge attribute to use for 61 | assigning edge values.} 62 | 63 | \item{add.edges}{logical; should new edges be added to \code{x} where edges 64 | are absent and the appropriate element of \code{value} is non-zero?} 65 | 66 | \item{value}{the value (or set thereof) to be assigned to the selected 67 | element of \code{x}.} 68 | 69 | \item{attrname}{the name of a network or vertex attribute (as appropriate).} 70 | } 71 | \value{ 72 | The extracted data, or none. 73 | } 74 | \description{ 75 | Various operators which allow extraction or replacement of various 76 | components of a \code{network} object. 77 | } 78 | \details{ 79 | Indexing for edge extraction operates in a manner analogous to \code{matrix} 80 | objects. Thus, \code{x[,]} selects all vertex pairs, \code{x[1,-5]} selects 81 | the pairing of vertex 1 with all vertices except for 5, etc. Following 82 | this, it is acceptable for \code{i} and/or \code{j} to be logical vectors 83 | indicating which vertices are to be included. During assignment, an attempt 84 | is made to match the elements of \code{value} to the extracted pairs in an 85 | intelligent way; in particular, elements of \code{value} will be replicated 86 | if too few are supplied (allowing expressions like \code{x[1,]<-1}). Where 87 | \code{names.eval==NULL}, zero and non-zero values are taken to indicate the 88 | presence of absence of edges. \code{x[2,4]<-6} thus adds a single (2,4) 89 | edge to \code{x}, and \code{x[2,4]<-0} removes such an edge (if present). 90 | If \code{x} is multiplex, assigning 0 to a vertex pair will eliminate 91 | \emph{all} edges on that pair. Pairs are taken to be directed where 92 | \code{is.directed(x)==TRUE}, and undirected where 93 | \code{is.directed(x)==FALSE}. 94 | 95 | If an edge attribute is specified using \code{names.eval}, then the provided 96 | values will be assigned to that attribute. When assigning values, only 97 | extant edges are employed (unless \code{add.edges==TRUE}); in the latter 98 | case, any non-zero assignment results in the addition of an edge where 99 | currently absent. If the attribute specified is not present on a given 100 | edge, it is added. Otherwise, any existing value is overwritten. The 101 | \code{\%e\%} operator can also be used to extract/assign edge values; in those 102 | roles, it is respectively equivalent to \code{get.edge.value(x,attrname)} 103 | and \code{set.edge.value(x,attrname=attrname,value=value)} (if \code{value} 104 | is a matrix) and \code{set.edge.attribute(x,attrname=attrname,value=value)} 105 | (if \code{value} is anything else). That is, if \code{value} is a matrix, 106 | the assignment operator treats it as an adjacency matrix; and if not, it 107 | treats it as a vector (recycled as needed) in the internal ordering of edges 108 | (i.e., edge IDs), skipping over deleted edges. In no case will attributes be 109 | assigned to nonexisted edges. 110 | 111 | The \code{\%n\%} and \code{\%v\%} operators serve as front-ends to the network 112 | and vertex extraction/assignment functions (respectively). In the 113 | extraction case, \code{x \%n\% attrname} is equivalent to 114 | \code{get.network.attribute(x,attrname)}, with \code{x \%v\% attrname} 115 | corresponding to \code{get.vertex.attribute(x,attrname)}. In assignment, 116 | the respective equivalences are to 117 | \code{set.network.attribute(x,attrname,value)} and 118 | \code{set.vertex.attribute(x,attrname,value)}. Note that the \code{\%\%} 119 | assignment forms are generally slower than the named versions of the 120 | functions beause they will trigger an additional internal copy of the 121 | network object. 122 | 123 | The \code{\%eattr\%}, \code{\%nattr\%}, and \code{\%vattr\%} operators are 124 | equivalent to \code{\%e\%}, \code{\%n\%}, and \code{\%v\%} (respectively). The 125 | short forms are more succinct, but may produce less readable code. 126 | } 127 | \examples{ 128 | 129 | #Create a random graph (inefficiently) 130 | g<-network.initialize(10) 131 | g[,]<-matrix(rbinom(100,1,0.1),10,10) 132 | plot(g) 133 | 134 | #Demonstrate edge addition/deletion 135 | g[,]<-0 136 | g[1,]<-1 137 | g[2:3,6:7]<-1 138 | g[,] 139 | 140 | #Set edge values 141 | g[,,names.eval="boo"]<-5 142 | as.sociomatrix(g,"boo") 143 | #Assign edge values from a vector 144 | g \%e\% "hoo" <- "wah" 145 | g \%e\% "hoo" 146 | g \%e\% "om" <- c("wow","whee") 147 | g \%e\% "om" 148 | #Assign edge values as a sociomatrix 149 | g \%e\% "age" <- matrix(1:100, 10, 10) 150 | g \%e\% "age" 151 | as.sociomatrix(g,"age") 152 | 153 | #Set/retrieve network and vertex attributes 154 | g \%n\% "blah" <- "Pork!" #The other white meat? 155 | g \%n\% "blah" == "Pork!" #TRUE! 156 | g \%v\% "foo" <- letters[10:1] #Letter the vertices 157 | g \%v\% "foo" == letters[10:1] #All TRUE 158 | 159 | } 160 | \references{ 161 | Butts, C. T. (2008). \dQuote{network: a Package for Managing 162 | Relational Data in R.} \emph{Journal of Statistical Software}, 24(2). 163 | \doi{10.18637/jss.v024.i02} 164 | } 165 | \seealso{ 166 | \code{\link{is.adjacent}}, \code{\link{as.sociomatrix}}, 167 | \code{\link{attribute.methods}}, \code{\link{add.edges}}, 168 | \code{\link{network.operators}}, and \code{\link{get.inducedSubgraph}} 169 | } 170 | \author{ 171 | Carter T. Butts \email{buttsc@uci.edu} 172 | } 173 | \keyword{graphs} 174 | \keyword{manip} 175 | -------------------------------------------------------------------------------- /man/network.indicators.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/access.R 3 | \name{network.indicators} 4 | \alias{network.indicators} 5 | \alias{has.loops} 6 | \alias{is.bipartite} 7 | \alias{is.bipartite.network} 8 | \alias{is.directed} 9 | \alias{is.directed.network} 10 | \alias{is.hyper} 11 | \alias{is.multiplex} 12 | \title{Indicator Functions for Network Properties} 13 | \usage{ 14 | has.loops(x) 15 | 16 | is.bipartite(x, ...) 17 | 18 | \method{is.bipartite}{network}(x, ...) 19 | 20 | is.directed(x, ...) 21 | 22 | \method{is.directed}{network}(x, ...) 23 | 24 | is.hyper(x) 25 | 26 | is.multiplex(x) 27 | } 28 | \arguments{ 29 | \item{x}{an object of class \code{network}} 30 | 31 | \item{...}{other arguments passed to/from other methods} 32 | } 33 | \value{ 34 | \code{TRUE} or \code{FALSE} 35 | } 36 | \description{ 37 | Various indicators for properties of \code{network} class objects. 38 | } 39 | \details{ 40 | These methods are the standard means of assessing the state of a 41 | \code{network} object; other methods can (and should) use these routines in 42 | governing their own behavior. As such, improper setting of the associated 43 | attributes may result in unpleasantly creative results. (See the 44 | \code{edge.check} argument to \code{\link{add.edges}} for an example of code 45 | which makes use of these network properties.) 46 | 47 | The functions themselves behave has follows: 48 | 49 | \code{has.loops} returns \code{TRUE} iff \code{x} is allowed to contain 50 | loops (or loop-like edges, in the hypergraphic case). 51 | 52 | \code{is.bipartite} returns \code{TRUE} iff the \code{x} has been explicitly 53 | bipartite-coded. Values of \code{bipartite=NULL}, and \code{bipartite=FALSE} 54 | will evaluate to \code{FALSE}, numeric values of \code{bipartite>=0} will 55 | evaluate to \code{TRUE}. (The value \code{bipartite==0} indicates that it is 56 | a bipartite network with a zero-sized first partition.) Note that 57 | \code{is.bipartite} refers only to the storage properties of \code{x} and 58 | how it should be treated by some algorithms; \code{is.bipartite(x)==FALSE} 59 | it does \emph{not} mean that \code{x} cannot admit a bipartition! 60 | 61 | \code{is.directed} returns \code{TRUE} iff the edges of \code{x} are to be 62 | interpreted as directed. 63 | 64 | \code{is.hyper} returns \code{TRUE} iff \code{x} is allowed to contain 65 | hypergraphic edges. 66 | 67 | \code{is.multiplex} returns \code{TRUE} iff \code{x} is allowed to contain 68 | multiplex edges. 69 | } 70 | \examples{ 71 | 72 | g<-network.initialize(5) #Initialize the network 73 | is.bipartite(g) 74 | is.directed(g) 75 | is.hyper(g) 76 | is.multiplex(g) 77 | has.loops(g) 78 | 79 | } 80 | \references{ 81 | Butts, C. T. (2008). \dQuote{network: a Package for Managing 82 | Relational Data in R.} \emph{Journal of Statistical Software}, 24(2). 83 | \doi{10.18637/jss.v024.i02} 84 | } 85 | \seealso{ 86 | \code{\link{network}}, \code{\link{get.network.attribute}}, 87 | \code{set.network.attribute}, \code{\link{add.edges}} 88 | } 89 | \author{ 90 | Carter T. Butts \email{buttsc@uci.edu} 91 | } 92 | \keyword{classes} 93 | \keyword{graphs} 94 | -------------------------------------------------------------------------------- /man/network.initialize.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/constructors.R 3 | \name{network.initialize} 4 | \alias{network.initialize} 5 | \title{Initialize a Network Class Object} 6 | \usage{ 7 | network.initialize( 8 | n, 9 | directed = TRUE, 10 | hyper = FALSE, 11 | loops = FALSE, 12 | multiple = FALSE, 13 | bipartite = FALSE 14 | ) 15 | } 16 | \arguments{ 17 | \item{n}{the number of vertices to initialize} 18 | 19 | \item{directed}{logical; should edges be interpreted as directed?} 20 | 21 | \item{hyper}{logical; are hyperedges allowed?} 22 | 23 | \item{loops}{logical; should loops be allowed?} 24 | 25 | \item{multiple}{logical; are multiplex edges allowed?} 26 | 27 | \item{bipartite}{count; should the network be interpreted as bipartite? If 28 | present (i.e., non-NULL) it is the count of the number of actors in the 29 | first mode of the bipartite network. In this case, the overall number of 30 | vertices is equal to the number of 'actors' (first mode) plus the number of 31 | `events' (second mode), with the vertex.ids of all actors preceeding all 32 | events. The edges are then interpreted as nondirected.} 33 | } 34 | \value{ 35 | An object of class \code{network} 36 | } 37 | \description{ 38 | Create and initialize a \code{network} object with \code{n} vertices. 39 | } 40 | \details{ 41 | Generally, \code{network.initialize} is called by other constructor 42 | functions as part of the process of creating a network. 43 | } 44 | \examples{ 45 | 46 | g<-network.initialize(5) #Create an empty graph on 5 vertices 47 | 48 | } 49 | \references{ 50 | Butts, C. T. (2008). \dQuote{network: a Package for Managing 51 | Relational Data in R.} \emph{Journal of Statistical Software}, 24(2). 52 | \doi{10.18637/jss.v024.i02} 53 | } 54 | \seealso{ 55 | \code{\link{network}}, \code{\link{as.network.matrix}} 56 | } 57 | \author{ 58 | Carter T. Butts \email{buttsc@uci.edu} 59 | } 60 | \keyword{classes} 61 | \keyword{graphs} 62 | -------------------------------------------------------------------------------- /man/network.loop.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot.R 3 | \name{network.loop} 4 | \alias{network.loop} 5 | \title{Add Loops to a Plot} 6 | \usage{ 7 | network.loop( 8 | x0, 9 | y0, 10 | length = 0.1, 11 | angle = 10, 12 | width = 0.01, 13 | col = 1, 14 | border = 1, 15 | lty = 1, 16 | offset = 0, 17 | edge.steps = 10, 18 | radius = 1, 19 | arrowhead = TRUE, 20 | xctr = 0, 21 | yctr = 0, 22 | ... 23 | ) 24 | } 25 | \arguments{ 26 | \item{x0}{a vector of x coordinates for points of origin.} 27 | 28 | \item{y0}{a vector of y coordinates for points of origin.} 29 | 30 | \item{length}{arrowhead length, in current plotting units.} 31 | 32 | \item{angle}{arrowhead angle (in degrees).} 33 | 34 | \item{width}{width for loop body, in current plotting units (can be a 35 | vector).} 36 | 37 | \item{col}{loop body color (can be a vector).} 38 | 39 | \item{border}{loop border color (can be a vector).} 40 | 41 | \item{lty}{loop border line type (can be a vector).} 42 | 43 | \item{offset}{offset for origin point (can be a vector).} 44 | 45 | \item{edge.steps}{number of steps to use in approximating curves.} 46 | 47 | \item{radius}{loop radius (can be a vector).} 48 | 49 | \item{arrowhead}{boolean; should arrowheads be used? (Can be a vector.)} 50 | 51 | \item{xctr}{x coordinate for the central location away from which loops 52 | should be oriented.} 53 | 54 | \item{yctr}{y coordinate for the central location away from which loops 55 | should be oriented.} 56 | 57 | \item{\dots}{additional arguments to \code{\link{polygon}}.} 58 | } 59 | \value{ 60 | None. 61 | } 62 | \description{ 63 | \code{network.loop} draws a "loop" at a specified location; this is used to 64 | designate self-ties in \code{\link{plot.network}}. 65 | } 66 | \details{ 67 | \code{network.loop} is the companion to \code{\link{network.arrow}}; like 68 | the latter, plot elements produced by \code{network.loop} are drawn using 69 | \code{\link{polygon}}, and as such are scaled based on the current plotting 70 | device. By default, loops are drawn so as to encompass a circular region of 71 | radius \code{radius}, whose center is \code{offset} units from \code{x0,y0} 72 | and at maximum distance from \code{xctr,yctr}. This is useful for functions 73 | like \code{\link{plot.network}}, which need to draw loops incident to 74 | vertices of varying radii. 75 | } 76 | \note{ 77 | \code{network.loop} is a direct adaptation of 78 | \code{\link[sna]{gplot.loop}}, from the \code{sna} package. 79 | } 80 | \examples{ 81 | 82 | #Plot a few polygons with loops 83 | plot(0,0,type="n",xlim=c(-2,2),ylim=c(-2,2),asp=1) 84 | network.loop(c(0,0),c(1,-1),col=c(3,2),width=0.05,length=0.4, 85 | offset=sqrt(2)/4,angle=20,radius=0.5,edge.steps=50,arrowhead=TRUE) 86 | polygon(c(0.25,-0.25,-0.25,0.25,NA,0.25,-0.25,-0.25,0.25), 87 | c(1.25,1.25,0.75,0.75,NA,-1.25,-1.25,-0.75,-0.75),col=c(2,3)) 88 | 89 | 90 | } 91 | \seealso{ 92 | \code{\link{network.arrow}}, \code{\link{plot.network}}, 93 | \code{\link{polygon}} 94 | } 95 | \author{ 96 | Carter T. Butts \email{buttsc@uci.edu} 97 | } 98 | \keyword{aplot} 99 | \keyword{graphs} 100 | -------------------------------------------------------------------------------- /man/network.naedgecount.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/access.R 3 | \name{missing.edges} 4 | \alias{missing.edges} 5 | \alias{is.na.network} 6 | \alias{network.naedgecount} 7 | \title{Identifying and Counting Missing Edges in a Network Object} 8 | \usage{ 9 | \method{is.na}{network}(x) 10 | 11 | network.naedgecount(x, ...) 12 | } 13 | \arguments{ 14 | \item{x}{an object of class \code{network}} 15 | 16 | \item{\dots}{additional arguments, not used} 17 | } 18 | \value{ 19 | \code{is.na(x)} returns a network object, and 20 | \code{network.naedgecount(x)} returns the number of missing edges. 21 | } 22 | \description{ 23 | \code{network.naedgecount} returns the number of edges within a 24 | \code{network} object which are flagged as missing. The \code{is.na} 25 | network method returns a new network containing the missing edges. 26 | } 27 | \details{ 28 | The missingness of an edge is controlled by its \code{na} attribute (which 29 | is mandatory for all edges); \code{network.naedgecount} returns the number 30 | of edges for which \code{na==TRUE}. The \code{is.na} network method 31 | produces a new network object whose edges correspond to the missing 32 | (\code{na==TRUE}) edges of the original object, and is thus a covenient 33 | method of extracting detailed missingness information on the entire network. 34 | The network returned by \code{is.na} is guaranteed to have the same base 35 | network attributes (directedness, loopness, hypergraphicity, multiplexity, 36 | and bipartite constraint) as the original network object, but no other 37 | information is copied; note too that edge IDs are \emph{not} preserved by 38 | this process (although adjacency obviously is). Since the resulting object 39 | is a \code{\link{network}}, standard coercion, print/summary, and other 40 | methods can be applied to it in the usual fashion. 41 | 42 | It should be borne in mind that \dQuote{missingness} in the sense used here 43 | reflects the assertion that an edge's presence or absence is unknown, 44 | \emph{not} that said edge is known not to be present. Thus, the \code{na} 45 | count for an empty graph is properly 0, since all edges are known to be 46 | absent. Edges can be flagged as missing by setting their \code{na} 47 | attribute to \code{TRUE} using \code{\link{set.edge.attribute}}, or by 48 | appropriate use of the network assignment operators; see below for an 49 | example of the latter. 50 | } 51 | \examples{ 52 | 53 | #Create an empty network with no missing data 54 | g<-network.initialize(5) 55 | g[,] #No edges present.... 56 | network.naedgecount(g)==0 #Edges not present are not "missing"! 57 | 58 | #Now, add some missing edges 59 | g[1,,add.edges=TRUE]<-NA #Establish that 1's ties are unknown 60 | g[,] #Observe the missing elements 61 | is.na(g) #Observe in network form 62 | network.naedgecount(g)==4 #These elements do count! 63 | network.edgecount(is.na(g)) #Same as above 64 | 65 | 66 | } 67 | \references{ 68 | Butts, C. T. (2008). \dQuote{network: a Package for Managing 69 | Relational Data in R.} \emph{Journal of Statistical Software}, 24(2). 70 | \doi{10.18637/jss.v024.i02} 71 | } 72 | \seealso{ 73 | \code{\link{network.edgecount}}, 74 | \code{\link{get.network.attribute}}, \code{is.adjacent}, \code{\link{is.na}} 75 | } 76 | \author{ 77 | Carter T. Butts \email{buttsc@uci.edu} 78 | } 79 | \keyword{classes} 80 | \keyword{graphs} 81 | -------------------------------------------------------------------------------- /man/network.size.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/access.R 3 | \name{network.size} 4 | \alias{network.size} 5 | \title{Return the Size of a Network} 6 | \usage{ 7 | network.size(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{an object of class \code{network}} 11 | 12 | \item{\dots}{additional arguments, not used} 13 | } 14 | \value{ 15 | The network size 16 | } 17 | \description{ 18 | \code{network.size} returns the order of its argument (i.e., number of 19 | vertices). 20 | } 21 | \details{ 22 | \code{network.size(x)} is equivalent to \code{get.network.attribute(x,"n")}; 23 | the function exists as a convenience. 24 | } 25 | \examples{ 26 | 27 | #Initialize a network 28 | g<-network.initialize(7) 29 | network.size(g) 30 | 31 | } 32 | \references{ 33 | Butts, C. T. (2008). \dQuote{network: a Package for Managing 34 | Relational Data in R.} \emph{Journal of Statistical Software}, 24(2). 35 | \doi{10.18637/jss.v024.i02} 36 | } 37 | \seealso{ 38 | \code{\link{get.network.attribute}} 39 | } 40 | \author{ 41 | Carter T. Butts \email{buttsc@uci.edu} 42 | } 43 | \keyword{classes} 44 | \keyword{graphs} 45 | -------------------------------------------------------------------------------- /man/network.vertex.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot.R 3 | \name{network.vertex} 4 | \alias{network.vertex} 5 | \title{Add Vertices to a Plot} 6 | \usage{ 7 | network.vertex( 8 | x, 9 | y, 10 | radius = 1, 11 | sides = 4, 12 | border = 1, 13 | col = 2, 14 | lty = NULL, 15 | rot = 0, 16 | lwd = 1, 17 | ... 18 | ) 19 | } 20 | \arguments{ 21 | \item{x}{a vector of x coordinates.} 22 | 23 | \item{y}{a vector of y coordinates.} 24 | 25 | \item{radius}{a vector of vertex radii.} 26 | 27 | \item{sides}{a vector containing the number of sides to draw for each 28 | vertex.} 29 | 30 | \item{border}{a vector of vertex border colors.} 31 | 32 | \item{col}{a vector of vertex interior colors.} 33 | 34 | \item{lty}{a vector of vertex border line types.} 35 | 36 | \item{rot}{a vector of vertex rotation angles (in degrees).} 37 | 38 | \item{lwd}{a vector of vertex border line widths.} 39 | 40 | \item{\dots}{Additional arguments to \code{\link{polygon}}} 41 | } 42 | \value{ 43 | None 44 | } 45 | \description{ 46 | \code{network.vertex} adds one or more vertices (drawn using 47 | \code{\link{polygon}}) to a plot. 48 | } 49 | \details{ 50 | \code{network.vertex} draws regular polygons of specified radius and number 51 | of sides, at the given coordinates. This is useful for routines such as 52 | \code{\link{plot.network}}, which use such shapes to depict vertices. 53 | } 54 | \note{ 55 | \code{network.vertex} is a direct adaptation of 56 | \code{\link[sna]{gplot.vertex}} from the \code{sna} package. 57 | } 58 | \examples{ 59 | 60 | 61 | #Open a plot window, and place some vertices 62 | plot(0,0,type="n",xlim=c(-1.5,1.5),ylim=c(-1.5,1.5),asp=1) 63 | network.vertex(cos((1:10)/10*2*pi),sin((1:10)/10*2*pi),col=1:10, 64 | sides=3:12,radius=0.1) 65 | 66 | 67 | } 68 | \references{ 69 | Butts, C. T. (2008). \dQuote{network: a Package for Managing 70 | Relational Data in R.} \emph{Journal of Statistical Software}, 24(2). 71 | \doi{10.18637/jss.v024.i02} 72 | } 73 | \seealso{ 74 | \code{\link{plot.network}}, \code{\link{polygon}} 75 | } 76 | \author{ 77 | Carter T. Butts \email{buttsc@uci.edu} 78 | } 79 | \keyword{aplot} 80 | \keyword{graphs} 81 | -------------------------------------------------------------------------------- /man/permute.vertexIDs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/access.R 3 | \name{permute.vertexIDs} 4 | \alias{permute.vertexIDs} 5 | \alias{permute.vertexIDs.network} 6 | \title{Permute (Relabel) the Vertices Within a Network} 7 | \usage{ 8 | permute.vertexIDs(x, vids, ...) 9 | 10 | \method{permute.vertexIDs}{network}(x, vids, ...) 11 | } 12 | \arguments{ 13 | \item{x}{an object of class \code{\link{network}}.} 14 | 15 | \item{vids}{a vector of vertex IDs, in the order to which they are to be 16 | permuted.} 17 | 18 | \item{...}{additional arguments to methods.} 19 | } 20 | \value{ 21 | Invisibly, a pointer to the permuted network. 22 | \code{permute.vertexIDs} modifies its argument in place. 23 | } 24 | \description{ 25 | \code{permute.vertexIDs} permutes the vertices within a given network in the 26 | specified fashion. Since this occurs internally (at the level of vertex 27 | IDs), it is rarely of interest to end-users. 28 | } 29 | \details{ 30 | \code{permute.vertexIDs} alters the internal ordering of vertices within a 31 | \code{\link{network}}. For most practical applications, this should not be 32 | necessary -- de facto permutation can be accomplished by altering the 33 | appropriate vertex attributes. \code{permute.vertexIDs} is needed for 34 | certain other routines (such as \code{\link{delete.vertices}}), where it is 35 | used in various arcane and ineffable ways. 36 | } 37 | \examples{ 38 | 39 | data(flo) #Load the Florentine Families data 40 | nflo<-network(flo) #Create a network object 41 | n<-network.size(nflo) #Get the number of vertices 42 | permute.vertexIDs(nflo,n:1) #Reverse the vertices 43 | all(flo[n:1,n:1]==as.sociomatrix(nflo)) #Should be TRUE 44 | 45 | } 46 | \references{ 47 | Butts, C. T. (2008). \dQuote{network: a Package for Managing 48 | Relational Data in R.} \emph{Journal of Statistical Software}, 24(2). 49 | \doi{10.18637/jss.v024.i02} 50 | } 51 | \seealso{ 52 | \code{\link{network}} 53 | } 54 | \author{ 55 | Carter T. Butts \email{buttsc@uci.edu} 56 | } 57 | \keyword{graphs} 58 | \keyword{manip} 59 | -------------------------------------------------------------------------------- /man/preparePlotArgs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot.R 3 | \name{plotArgs.network} 4 | \alias{plotArgs.network} 5 | \title{Expand and transform attributes of networks to values appropriate for 6 | aguments to plot.network} 7 | \usage{ 8 | plotArgs.network(x, argName, argValue, d = NULL, edgetouse = NULL) 9 | } 10 | \arguments{ 11 | \item{x}{a \code{network} object which is going to be plotted} 12 | 13 | \item{argName}{character, the name of \code{plot.network} graphic parameter} 14 | 15 | \item{argValue}{value for the graphic paramter named in \code{argName} which 16 | to be transformed/prepared. For many attributes, if this is a single 17 | character vector it will be assumed to be the name of a vertex or edge 18 | attribute to be extracted and transformed} 19 | 20 | \item{d}{is an edgelist matrix of edge values optionally used by some edge 21 | attribute functions} 22 | 23 | \item{edgetouse}{numeric vector giving set of edge ids to be used (in case 24 | some edges are not being shown) required by some attributes} 25 | } 26 | \value{ 27 | returns a vector with length corresponding to the number of vertices 28 | or edges (depending on the paramter type) giving the appropriately prepared 29 | values for the parameter type. If the values or specified attribute can not 30 | be processed correctly, and Error may occur. 31 | } 32 | \description{ 33 | This is primairly an internal function called by \code{plot.network} or by 34 | external packages such as \code{ndtv} that want to prepare 35 | \code{plot.network} graphic arguments in a standardized way. 36 | } 37 | \details{ 38 | Given a network object, the name of graphic parameter argument to 39 | \code{plot.network} and value, it will if necessary transform the value, or 40 | extract it from the network, according to the description in 41 | \code{\link{plot.network}}. For some attributes, if the value is the name of 42 | a vertex or edge attribute, the appropriate values will be extracted from 43 | the network before transformation. 44 | } 45 | \examples{ 46 | 47 | net<-network.initialize(3) 48 | set.vertex.attribute(net,'color',c('red','green','blue')) 49 | set.vertex.attribute(net,'charm',1:3) 50 | # replicate a single colorname value 51 | plotArgs.network(net,'vertex.col','purple') 52 | # map the 'color' attribute to color 53 | plotArgs.network(net,'vertex.col','color') 54 | # similarly for a numeric attribute ... 55 | plotArgs.network(net,'vertex.cex',12) 56 | plotArgs.network(net,'vertex.cex','charm') 57 | 58 | } 59 | \seealso{ 60 | See also \code{\link{plot.network}} 61 | } 62 | \author{ 63 | skyebend@uw.edu 64 | } 65 | -------------------------------------------------------------------------------- /man/prod.network.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/operators.R 3 | \name{prod.network} 4 | \alias{prod.network} 5 | \title{Combine Networks by Edge Value Multiplication} 6 | \usage{ 7 | \method{prod}{network}(..., attrname = NULL, na.rm = FALSE) 8 | } 9 | \arguments{ 10 | \item{\dots}{one or more \code{network} objects.} 11 | 12 | \item{attrname}{the name of an edge attribute to use when assessing edge 13 | values, if desired.} 14 | 15 | \item{na.rm}{logical; should edges with missing data be ignored?} 16 | } 17 | \value{ 18 | A \code{\link{network}} object. 19 | } 20 | \description{ 21 | Given a series of networks, \code{prod.network} attempts to form a new 22 | network by multiplication of edges. If a non-null \code{attrname} is given, 23 | the corresponding edge attribute is used to determine and store edge values. 24 | } 25 | \details{ 26 | The network product method attempts to combine its arguments by edgewise 27 | multiplication (\emph{not} composition) of their respective adjacency 28 | matrices; thus, this method is only applicable for networks whose adjacency 29 | coercion is well-behaved. Multiplication is effectively boolean unless 30 | \code{attrname} is specified, in which case this is used to assess edge 31 | values -- net values of 0 will result in removal of the underlying edge. 32 | 33 | Other network attributes in the return value are carried over from the first 34 | element in the list, so some persistence is possible (unlike the 35 | multiplication operator). Note that it is sometimes possible to 36 | \dQuote{multiply} networks and raw adjacency matrices using this routine (if 37 | all dimensions are correct), but more exotic combinations may result in 38 | regrettably exciting behavior. 39 | } 40 | \examples{ 41 | 42 | #Create some networks 43 | g<-network.initialize(5) 44 | h<-network.initialize(5) 45 | i<-network.initialize(5) 46 | g[1:3,,names.eval="marsupial",add.edges=TRUE]<-1 47 | h[1:2,,names.eval="marsupial",add.edges=TRUE]<-2 48 | i[1,,names.eval="marsupial",add.edges=TRUE]<-3 49 | 50 | #Combine by addition 51 | pouch<-prod(g,h,i,attrname="marsupial") 52 | pouch[,] #Edge values in the pouch? 53 | as.sociomatrix(pouch,attrname="marsupial") #Recover the marsupial 54 | 55 | } 56 | \references{ 57 | Butts, C. T. (2008). \dQuote{network: a Package for Managing 58 | Relational Data in R.} \emph{Journal of Statistical Software}, 24(2). 59 | \doi{10.18637/jss.v024.i02} 60 | } 61 | \seealso{ 62 | \code{\link{network.operators}} 63 | } 64 | \author{ 65 | Carter T. Butts \email{buttsc@uci.edu} 66 | } 67 | \keyword{arith} 68 | \keyword{graphs} 69 | -------------------------------------------------------------------------------- /man/read.paj.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fileio.R 3 | \name{read.paj} 4 | \alias{read.paj} 5 | \alias{read.paj.simplify} 6 | \alias{switchArcDirection} 7 | \alias{readAndVectorizeLine} 8 | \title{Read a Pajek Project or Network File and Convert to an R 'Network' Object} 9 | \usage{ 10 | read.paj( 11 | file, 12 | verbose = FALSE, 13 | debug = FALSE, 14 | edge.name = NULL, 15 | simplify = FALSE, 16 | time.format = c("pajekTiming", "networkDynamic") 17 | ) 18 | } 19 | \arguments{ 20 | \item{file}{the name of the file whence the data are to be read. If it does 21 | not contain an absolute path, the file name is relative to the current 22 | working directory (as returned by \code{\link{getwd}}). \code{file} can 23 | also be a complete URL.} 24 | 25 | \item{verbose}{logical: Should longer descriptions of the reading and 26 | coercion process be printed out?} 27 | 28 | \item{debug}{logical: Should very detailed descriptions of the reading and 29 | coercion process be printed out? This is typically used to debug the reading 30 | of files that are corrupted on coercion.} 31 | 32 | \item{edge.name}{optional name for the edge variable read from the file. The 33 | default is to use the value in the project file if found.} 34 | 35 | \item{simplify}{Should the returned network be simplified as much as 36 | possible and saved? The values specifies the name of the file which the data 37 | are to be stored. If it does not contain an absolute path, the file name is 38 | relative to the current working directory (see \code{\link{getwd}}). If 39 | \code{specify} is TRUE the file name is the name \code{file}.} 40 | 41 | \item{time.format}{if the network has timing information attached to 42 | edges/vertices, how should it be processed? \code{'pajekTiming'} will 43 | attach the timing information unchanged in an attribute named 44 | \code{pajek.timing}. \code{'networkDynamic'} will translate it to a spell 45 | matrix format, attach it as an \code{'activity'} attribute and add the class 46 | \code{'networkDynamic'} -- formating it for use by the \code{networkDynamic} 47 | package.} 48 | } 49 | \value{ 50 | The structure of the object returned by \code{read.paj} depends on 51 | the contents of the file it parses. \itemize{ \item if input file contains 52 | information about a single 'network' object (i.e .net input file) a single 53 | network object is returned with attribute data set appropriately if 54 | possible. or a list of networks (for .paj input). \item if input file 55 | contains multiple sets of relations for a single network, a list of network 56 | objects ('network.series') is returned, along with a formula object?. \item 57 | if input .paj file contains additional information (like partition 58 | information), or multiple \code{*Network} definitions a two element list is 59 | returned. The first element is a list of all the network objects created, 60 | and the second is a list of partitions, etc. (how are these matched up) } 61 | } 62 | \description{ 63 | Return a (list of) \code{\link{network}} object(s) after reading a 64 | corresponding .net or .paj file. The code accepts ragged array edgelists, 65 | but cannot currently handle 2-mode, multirelational (e.g. KEDS), or networks 66 | with entries for both edges and arcs (e.g. GD-a99m). See \code{network}, 67 | \code{statnet}, or \code{sna} for more information. 68 | } 69 | \details{ 70 | If the \code{*Vertices} block includes the optional graphic attributes 71 | (coordinates, shape, size, etc.) they will be read attached to the network 72 | as vertex attributes but values will not be interperted (i.e. Pajek's color 73 | names will not be translated to R color names). Vertex attributes included 74 | in a \code{*Vector} block will be attached as vertex attributes. 75 | 76 | Edges or Arc weights in the \code{*Arcs} or \code{*Edges} block are include 77 | in the network as an attribute with the same name as the network. If no 78 | weight is included, a default weight of 1 is used. Optional graphic 79 | attributes or labels will be attached as edge attributes. 80 | 81 | If the file contains an empty \code{Arcs} block, an undirected network will 82 | be returned. Otherwise the network will be directed, with two edges (one in 83 | each direction) added for every row in the \code{*Edges} block. 84 | 85 | If the \code{*Vertices}, \code{*Arcs} or \code{*Edges} blocks having timing 86 | information included in the rows (indicated by \code{...} tokens), it will be 87 | attached to the vertices with behavior determined by the \code{time.format} 88 | option. If the \code{'networkDynamic'} format is used, times will be 89 | translated to \code{networkDynamic}'s spell model with the assumtion that 90 | the original Pajek representation was indicating discrete time chunks. For 91 | example \code{"[5-10]"} will become the spell \code{[5,11]}, \code{"[2-*]"} 92 | will become \code{[2,Inf]} and \code{"[7]"} will become \code{[7,8]}. See 93 | documentation for \code{networkDynamic}'s \code{?activity.attribute} for 94 | details. 95 | 96 | The \code{*Arcslist}, \code{*Edgelist} and \code{*Events} blocks are not yet 97 | supported. 98 | 99 | As there is no known single complete specification for the file format, 100 | parsing behavior has been infered from references and examples below. 101 | } 102 | \examples{ 103 | 104 | \dontrun{ 105 | require(network) 106 | 107 | par(mfrow=c(2,2)) 108 | 109 | test.net.1 <- read.paj("http://vlado.fmf.uni-lj.si/pub/networks/data/GD/gd98/A98.net") 110 | plot(test.net.1,main=test.net.1\%n\%'title') 111 | 112 | test.net.2 <- read.paj("http://vlado.fmf.uni-lj.si/pub/networks/data/mix/USAir97.net") 113 | # plot using coordinates from the file in the file 114 | plot(test.net.2,main=test.net.2\%n\%'title', 115 | coord=cbind(test.net.2\%v\%'x', 116 | test.net.2\%v\%'y'), 117 | jitter=FALSE) 118 | 119 | # read .paj project file 120 | # notice output has $networks and $partitions 121 | read.paj('http://vlado.fmf.uni-lj.si/vlado/podstat/AO/net/Tina.paj') 122 | } 123 | 124 | } 125 | \references{ 126 | Batagelj, Vladimir and Mrvar, Andrej (2011) Pajek Reference 127 | Manual version 2.05 128 | \url{http://web.archive.org/web/20240906013709/http://vlado.fmf.uni-lj.si/pub/networks/pajek/doc/pajekman.pdf} Section 129 | 5.3 pp 73-79 130 | 131 | Batageli, Vladimir (2008) "Network Analysis Description of Networks" 132 | \url{http://web.archive.org/web/20240511173536/http://vlado.fmf.uni-lj.si/pub/networks/doc/ECPR/08/ECPR01.pdf} 133 | 134 | Pajek Datasets \url{http://web.archive.org/web/20240411203537/http://vlado.fmf.uni-lj.si/pub/networks/data/esna} 135 | } 136 | \seealso{ 137 | \code{\link{network}} 138 | } 139 | \author{ 140 | Dave Schruth \email{dschruth@u.washington.edu}, Mark S. Handcock 141 | \email{handcock@stat.washington.edu} (with additional input from Alex 142 | Montgomery \email{ahm@reed.edu}), Skye Bender-deMoll 143 | \email{skyebend@uw.edu} 144 | } 145 | \keyword{datasets} 146 | -------------------------------------------------------------------------------- /man/sum.network.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/operators.R 3 | \name{sum.network} 4 | \alias{sum.network} 5 | \title{Combine Networks by Edge Value Addition} 6 | \usage{ 7 | \method{sum}{network}(..., attrname = NULL, na.rm = FALSE) 8 | } 9 | \arguments{ 10 | \item{\dots}{one or more \code{network} objects.} 11 | 12 | \item{attrname}{the name of an edge attribute to use when assessing edge 13 | values, if desired.} 14 | 15 | \item{na.rm}{logical; should edges with missing data be ignored?} 16 | } 17 | \value{ 18 | A \code{\link{network}} object. 19 | } 20 | \description{ 21 | Given a series of networks, \code{sum.network} attempts to form a new 22 | network by accumulation of edges. If a non-null \code{attrname} is given, 23 | the corresponding edge attribute is used to determine and store edge values. 24 | } 25 | \details{ 26 | The network summation method attempts to combine its arguments by addition 27 | of their respective adjacency matrices; thus, this method is only applicable 28 | for networks whose adjacency coercion is well-behaved. Addition is 29 | effectively boolean unless \code{attrname} is specified, in which case this 30 | is used to assess edge values -- net values of 0 will result in removal of 31 | the underlying edge. 32 | 33 | Other network attributes in the return value are carried over from the first 34 | element in the list, so some persistence is possible (unlike the addition 35 | operator). Note that it is sometimes possible to \dQuote{add} networks and 36 | raw adjacency matrices using this routine (if all dimensions are correct), 37 | but more exotic combinations may result in regrettably exciting behavior. 38 | } 39 | \examples{ 40 | 41 | #Create some networks 42 | g<-network.initialize(5) 43 | h<-network.initialize(5) 44 | i<-network.initialize(5) 45 | g[1,,names.eval="marsupial",add.edges=TRUE]<-1 46 | h[1:2,,names.eval="marsupial",add.edges=TRUE]<-2 47 | i[1:3,,names.eval="marsupial",add.edges=TRUE]<-3 48 | 49 | #Combine by addition 50 | pouch<-sum(g,h,i,attrname="marsupial") 51 | pouch[,] #Edge values in the pouch? 52 | as.sociomatrix(pouch,attrname="marsupial") #Recover the marsupial 53 | 54 | } 55 | \references{ 56 | Butts, C. T. (2008). \dQuote{network: a Package for Managing 57 | Relational Data in R.} \emph{Journal of Statistical Software}, 24(2). 58 | \doi{10.18637/jss.v024.i02} 59 | } 60 | \seealso{ 61 | \code{\link{network.operators}} 62 | } 63 | \author{ 64 | Carter T. Butts \email{buttsc@uci.edu} 65 | } 66 | \keyword{arith} 67 | \keyword{graphs} 68 | -------------------------------------------------------------------------------- /man/valid.eids.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/access.R 3 | \name{valid.eids} 4 | \alias{valid.eids} 5 | \alias{valid.eids.network} 6 | \title{Get the ids of all the edges that are valid in a network} 7 | \usage{ 8 | valid.eids(x, ...) 9 | 10 | \method{valid.eids}{network}(x, ...) 11 | } 12 | \arguments{ 13 | \item{x}{a network object, possibly with some deleted edges.} 14 | 15 | \item{...}{additional arguments to methods.} 16 | } 17 | \value{ 18 | a vector of integer ids corresponding to the non-null edges in x 19 | } 20 | \description{ 21 | Returns a vector of valid edge ids (corresponding to non-NULL edges) for a 22 | network that may have some deleted edges. 23 | } 24 | \details{ 25 | The edge ids used in the network package are positional indices on the 26 | internal "mel" list. When edges are removed using \code{\link{delete.edges}} 27 | \code{NULL} elements are left on the list. The function \code{valid.eids} 28 | returns the ids of all the valid (non-null) edge ids for its \code{network} 29 | argument. 30 | } 31 | \note{ 32 | If it is known that x has no deleted edges, \code{seq_along(x$mel)} is 33 | a faster way to generate the sequence of possible edge ids. 34 | } 35 | \examples{ 36 | 37 | net<-network.initialize(100) 38 | add.edges(net,1:99,2:100) 39 | delete.edges(net,eid=5:95) 40 | # get the ids of the non-deleted edges 41 | valid.eids(net) 42 | 43 | } 44 | \seealso{ 45 | See also \code{\link{delete.edges}} 46 | } 47 | \author{ 48 | skyebend 49 | } 50 | -------------------------------------------------------------------------------- /man/which.matrix.type.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/misc.R 3 | \name{which.matrix.type} 4 | \alias{which.matrix.type} 5 | \title{Heuristic Determination of Matrix Types for Network Storage} 6 | \usage{ 7 | which.matrix.type(x) 8 | } 9 | \arguments{ 10 | \item{x}{a matrix, or an object of class \code{network}} 11 | } 12 | \value{ 13 | One of \code{"adjacency"}, \code{"incidence"}, or \code{"edgelist"} 14 | } 15 | \description{ 16 | \code{which.matrix.type} attempts to choose an appropriate matrix expression 17 | for a \code{network} object, or (if its argument is a matrix) attempts to 18 | determine whether the matrix is of type adjacency, incidence, or edgelist. 19 | } 20 | \details{ 21 | The heuristics used to determine matrix types are fairly arbitrary, and 22 | should be avoided where possible. This function is intended to provide a 23 | modestly intelligent fallback option when explicit identification by the 24 | user is not possible. 25 | } 26 | \examples{ 27 | 28 | #Create an arbitrary adjacency matrix 29 | m<-matrix(rbinom(25,1,0.5),5,5) 30 | diag(m)<-0 31 | 32 | #Can we guess the type? 33 | which.matrix.type(m) 34 | 35 | #Try the same thing with a network 36 | g<-network(m) 37 | which.matrix.type(g) 38 | which.matrix.type(as.matrix.network(g,matrix.type="incidence")) 39 | which.matrix.type(as.matrix.network(g,matrix.type="edgelist")) 40 | 41 | } 42 | \references{ 43 | Butts, C. T. (2008). \dQuote{network: a Package for Managing 44 | Relational Data in R.} \emph{Journal of Statistical Software}, 24(2). 45 | \doi{10.18637/jss.v024.i02} 46 | } 47 | \seealso{ 48 | \code{\link{as.matrix.network}}, \code{\link{as.network.matrix}} 49 | } 50 | \author{ 51 | David Hunter \email{dhunter@stat.psu.edu} 52 | } 53 | \keyword{graphs} 54 | -------------------------------------------------------------------------------- /src/Rinit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ###################################################################### 3 | # 4 | # utils.c 5 | # 6 | # Written by Jeffrey Horner 7 | # Last Modified 5/07/2016 8 | # Licensed under the GNU General Public License version 2 (June, 1991) 9 | # or greater 10 | # 11 | # Part of the R/network package 12 | # 13 | # This file contains the R/C initialization code 14 | # 15 | ###################################################################### 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include "access.h" 22 | #include "constructors.h" 23 | #include "layout.h" 24 | #include "utils.h" 25 | 26 | #define CALLDEF(name, n) {#name,(DL_FUNC) &name, n} 27 | static R_CallMethodDef CallEntries[] = { 28 | CALLDEF(addEdge_R,6), 29 | CALLDEF(addEdges_R,6), 30 | CALLDEF(addVertices_R,3), 31 | CALLDEF(copyNetwork_R,1), 32 | CALLDEF(deleteEdgeAttribute_R,2), 33 | CALLDEF(deleteEdges_R,2), 34 | CALLDEF(getEdgeAttribute_R,5), 35 | CALLDEF(deleteNetworkAttribute_R,2), 36 | CALLDEF(deleteVertexAttribute_R,2), 37 | CALLDEF(deleteVertices_R,2), 38 | CALLDEF(getEdgeIDs_R,5), 39 | CALLDEF(getEdges_R,5), 40 | CALLDEF(getNeighborhood_R,4), 41 | CALLDEF(isAdjacent_R,4), 42 | CALLDEF(isNANetwork_R,2), 43 | CALLDEF(networkEdgecount_R,2), 44 | CALLDEF(permuteVertexIDs_R,2), 45 | CALLDEF(setEdgeAttribute_R,4), 46 | CALLDEF(setEdgeAttributes_R,4), 47 | CALLDEF(setEdgeValue_R,4), 48 | CALLDEF(setNetworkAttribute_R,3), 49 | CALLDEF(setVertexAttribute_R,4), 50 | CALLDEF(setVertexAttributes_R,4), 51 | CALLDEF(nonEmptyEdges_R,1), 52 | {NULL,NULL,0} 53 | }; 54 | 55 | static R_CMethodDef CEntries[] = { 56 | CALLDEF(network_layout_fruchtermanreingold_R,15), 57 | CALLDEF(network_layout_kamadakawai_R,10), 58 | {NULL,NULL,0} 59 | }; 60 | 61 | void R_init_network(DllInfo *dll) 62 | { 63 | R_registerRoutines(dll,CEntries,CallEntries, NULL, NULL); 64 | R_useDynamicSymbols(dll, FALSE); 65 | 66 | 67 | /*Add back the various things required by the API.*/ 68 | 69 | /*Register access routines*/ 70 | R_RegisterCCallable("network", "getEdgeAttribute", (DL_FUNC) getEdgeAttribute); 71 | R_RegisterCCallable("network", "getEdgeIDs", (DL_FUNC) getEdgeIDs); 72 | R_RegisterCCallable("network", "getEdges", (DL_FUNC) getEdges); 73 | R_RegisterCCallable("network", "getNeighborhood", (DL_FUNC) getNeighborhood); 74 | R_RegisterCCallable("network", "getNetworkAttribute", (DL_FUNC) getNetworkAttribute); 75 | R_RegisterCCallable("network", "hasLoops", (DL_FUNC) hasLoops); 76 | R_RegisterCCallable("network", "isAdjacent", (DL_FUNC) isAdjacent); 77 | R_RegisterCCallable("network", "isDirected", (DL_FUNC) isDirected); 78 | R_RegisterCCallable("network", "isHyper", (DL_FUNC) isHyper); 79 | R_RegisterCCallable("network", "isLoop", (DL_FUNC) isLoop); 80 | R_RegisterCCallable("network", "isMultiplex", (DL_FUNC) isMultiplex); 81 | R_RegisterCCallable("network", "isNetwork", (DL_FUNC) isNetwork); 82 | R_RegisterCCallable("network", "networkEdgecount", (DL_FUNC) networkEdgecount); 83 | R_RegisterCCallable("network", "networkSize", (DL_FUNC) networkSize); 84 | 85 | /*Register modification routines*/ 86 | R_RegisterCCallable("network", "addEdge_R", (DL_FUNC) addEdge_R); 87 | R_RegisterCCallable("network", "addEdges_R", (DL_FUNC) addEdges_R); 88 | R_RegisterCCallable("network", "deleteEdgeAttribute", (DL_FUNC) deleteEdgeAttribute); 89 | R_RegisterCCallable("network", "deleteNetworkAttribute", (DL_FUNC) deleteNetworkAttribute); 90 | R_RegisterCCallable("network", "deleteVertexAttribute", (DL_FUNC) deleteVertexAttribute); 91 | R_RegisterCCallable("network", "setNetworkAttribute", (DL_FUNC) setNetworkAttribute); 92 | R_RegisterCCallable("network", "setVertexAttribute", (DL_FUNC) setVertexAttribute); 93 | 94 | /* Callable functions from other packages' C code */ 95 | #define RREGDEF(name) R_RegisterCCallable("network", #name, (DL_FUNC) name) 96 | RREGDEF(setListElement); 97 | RREGDEF(getListElement); 98 | } 99 | -------------------------------------------------------------------------------- /src/access.h: -------------------------------------------------------------------------------- 1 | /* 2 | ###################################################################### 3 | # 4 | # access.h 5 | # 6 | # Written by Carter T. Butts 7 | # Last Modified 7/07/16 8 | # Licensed under the GNU General Public License version 2 (June, 1991) 9 | # or greater 10 | # 11 | # Part of the R/network package 12 | # 13 | # This file contains headers for access.c. 14 | # 15 | ###################################################################### 16 | */ 17 | #ifndef ACCESS_H 18 | #define ACCESS_H 19 | 20 | 21 | /*DECLARATIONS/INCLUSIONS---------------------------------------------------*/ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | 33 | /*INTERNAL ROUTINES---------------------------------------------------------*/ 34 | 35 | SEXP deleteEdgeAttribute(SEXP x, int e, const char *attrname); 36 | 37 | SEXP deleteNetworkAttribute(SEXP x, const char *attrname); 38 | 39 | SEXP deleteVertexAttribute(SEXP x, int v, const char *attrname); 40 | 41 | SEXP getEdgeAttribute(SEXP x, int e, const char *str); 42 | 43 | SEXP getEdgeIDs(SEXP x, int v, int alter, const char *neighborhood, int naOmit); 44 | 45 | SEXP getEdges(SEXP x, int v, int alter, const char *neighborhood, int naOmit); 46 | 47 | SEXP getNeighborhood(SEXP x, int v, const char *type, int naOmit); 48 | 49 | SEXP getNetworkAttribute(SEXP x, const char *str); 50 | 51 | int hasLoops(SEXP x); 52 | 53 | int isAdjacent(SEXP x, int vi, int vj, int naOmit); 54 | 55 | int isDirected(SEXP x); 56 | 57 | int isHyper(SEXP x); 58 | 59 | int isLoop(SEXP outl, SEXP inl); 60 | 61 | int isMultiplex(SEXP x); 62 | 63 | int isNetwork(SEXP x); 64 | 65 | int networkEdgecount(SEXP x, int naOmit); 66 | 67 | int networkSize(SEXP x); 68 | 69 | SEXP setNetworkAttribute(SEXP x, const char *attrname, SEXP value); 70 | 71 | SEXP setVertexAttribute(SEXP x, const char *attrname, SEXP value, int v); 72 | 73 | SEXP deleteEdges(SEXP x, SEXP eid); 74 | 75 | SEXP permuteVertexIDs(SEXP x, SEXP vids); 76 | 77 | SEXP addEdges(SEXP x, SEXP tail, SEXP head, SEXP namesEval, SEXP valsEval, SEXP edgeCheck); 78 | 79 | /*R-CALLABLE ROUTINES-------------------------------------------------------*/ 80 | 81 | SEXP addEdge_R(SEXP x, SEXP tail, SEXP head, SEXP namesEval, SEXP valsEval, SEXP edgeCheck); 82 | 83 | SEXP addEdges_R(SEXP x, SEXP tail, SEXP head, SEXP namesEval, SEXP valsEval, SEXP edgeCheck); 84 | 85 | SEXP addVertices_R(SEXP x, SEXP nv, SEXP vattr); 86 | 87 | SEXP deleteEdgeAttribute_R(SEXP x, SEXP attrname); 88 | 89 | SEXP getEdgeAttribute_R(SEXP el,SEXP attrname, SEXP naomit,SEXP nullna,SEXP deletededgesomit); 90 | 91 | SEXP deleteEdges_R(SEXP x, SEXP eid); 92 | 93 | SEXP deleteNetworkAttribute_R(SEXP x, SEXP attrname); 94 | 95 | SEXP deleteVertexAttribute_R(SEXP x, SEXP attrname); 96 | 97 | SEXP deleteVertices_R(SEXP x, SEXP vid); 98 | 99 | SEXP getEdgeIDs_R(SEXP x, SEXP v, SEXP alter, SEXP neighborhood, SEXP naOmit); 100 | 101 | SEXP getEdges_R(SEXP x, SEXP v, SEXP alter, SEXP neighborhood, SEXP naOmit); 102 | 103 | SEXP getNeighborhood_R(SEXP x, SEXP v, SEXP type, SEXP naOmit); 104 | 105 | SEXP isAdjacent_R(SEXP x, SEXP vi, SEXP vj, SEXP naOmit); 106 | 107 | SEXP isNANetwork_R(SEXP x, SEXP y); 108 | 109 | SEXP networkEdgecount_R(SEXP x, SEXP naOmit); 110 | 111 | SEXP permuteVertexIDs_R(SEXP x, SEXP vids); 112 | 113 | SEXP setEdgeAttribute_R(SEXP x, SEXP attrname, SEXP value, SEXP e); 114 | 115 | SEXP setEdgeAttributes_R(SEXP x, SEXP attrname, SEXP value, SEXP e); 116 | 117 | SEXP setEdgeValue_R(SEXP x, SEXP attrname, SEXP value, SEXP e); 118 | 119 | SEXP setNetworkAttribute_R(SEXP x, SEXP attrname, SEXP value); 120 | 121 | SEXP setVertexAttribute_R(SEXP x, SEXP attrname, SEXP value, SEXP v); 122 | 123 | SEXP setVertexAttributes_R(SEXP x, SEXP attrname, SEXP value, SEXP v); 124 | 125 | SEXP nonEmptyEdges_R(SEXP el); 126 | 127 | #endif 128 | -------------------------------------------------------------------------------- /src/constructors.c: -------------------------------------------------------------------------------- 1 | /* 2 | ###################################################################### 3 | # 4 | # constructors.c 5 | # 6 | # Written by Carter T. Butts 7 | # Last Modified 03/04/19 8 | # Licensed under the GNU General Public License version 2 (June, 1991) 9 | # or greater 10 | # 11 | # Part of the R/network package 12 | # 13 | # This file contains routines related to constructor methods for 14 | # network objects. 15 | # 16 | ###################################################################### 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "utils.h" 25 | #include "constructors.h" 26 | 27 | 28 | /*INTERNAL ROUTINES----------------------------------------------------*/ 29 | 30 | 31 | 32 | /*R-CALLABLE ROUTINES--------------------------------------------------*/ 33 | 34 | 35 | SEXP copyEdges_R(SEXP x, SEXP y) 36 | /*Copy all edges from network x into network y. Note that y is assumed to have been initialized so as to have the same size as x.*/ 37 | { 38 | int pc=0; 39 | SEXP mel,mel2,iel,iel2,oel,oel2; 40 | 41 | mel=getListElement(x,"mel"); 42 | PROTECT(mel2=duplicate(mel)); pc++; 43 | PROTECT(y=setListElement(y,"mel",mel2)); pc++; 44 | iel=getListElement(x,"iel"); 45 | PROTECT(iel2=duplicate(iel)); pc++; 46 | PROTECT(y=setListElement(y,"iel",iel2)); pc++; 47 | oel=getListElement(x,"oel"); 48 | PROTECT(oel2=duplicate(oel)); pc++; 49 | y=setListElement(y,"oel",oel2); 50 | 51 | UNPROTECT(pc); 52 | return y; 53 | } 54 | 55 | 56 | SEXP copyNetwork_R(SEXP x) 57 | { 58 | int pc=0; 59 | SEXP y; 60 | 61 | PROTECT(y=duplicate(x)); pc++; 62 | 63 | UNPROTECT(pc); 64 | return y; 65 | } 66 | 67 | 68 | SEXP copyNetworkAttributes_R(SEXP x, SEXP y) 69 | /*Copy all network attributes from network x into network y.*/ 70 | { 71 | int pc=0; 72 | SEXP gal,gal2; 73 | 74 | gal=getListElement(x,"gal"); 75 | PROTECT(gal2=duplicate(gal)); pc++; 76 | y=setListElement(y,"gal",gal2); 77 | 78 | UNPROTECT(pc); 79 | return y; 80 | } 81 | 82 | 83 | SEXP copyVertexAttributes_R(SEXP x, SEXP y) 84 | /*Copy all vertex attributes from network x into network y. Note that y is assumed to have been initialized so as to have the same size as x.*/ 85 | { 86 | int pc=0; 87 | SEXP val,val2; 88 | 89 | val=getListElement(x,"val"); 90 | PROTECT(val2=duplicate(val)); pc++; 91 | y=setListElement(y,"val",val2); 92 | 93 | UNPROTECT(pc); 94 | return y; 95 | } 96 | 97 | -------------------------------------------------------------------------------- /src/constructors.h: -------------------------------------------------------------------------------- 1 | /* 2 | ###################################################################### 3 | # 4 | # constructors.h 5 | # 6 | # Written by Carter T. Butts 7 | # Last Modified 4/7/06 8 | # Licensed under the GNU General Public License version 2 (June, 1991) 9 | # or greater 10 | # 11 | # Part of the R/network package 12 | # 13 | # This file contains headers for constructors.c. 14 | # 15 | ###################################################################### 16 | */ 17 | #ifndef CONSTRUCTORS_H 18 | #define CONSTRUCTORS_H 19 | 20 | 21 | /*DECLARATIONS/INCLUSIONS---------------------------------------------------*/ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | 30 | /*INTERNAL ROUTINES---------------------------------------------------------*/ 31 | 32 | 33 | 34 | /*R-CALLABLE ROUTINES-------------------------------------------------------*/ 35 | 36 | SEXP copyEdges_R(SEXP x, SEXP y); 37 | 38 | SEXP copyNetwork_R(SEXP x); 39 | 40 | SEXP copyNetworkAttributes_R(SEXP x, SEXP y); 41 | 42 | SEXP copyVertexAttributes_R(SEXP x, SEXP y); 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /src/layout.h: -------------------------------------------------------------------------------- 1 | /* 2 | ###################################################################### 3 | # 4 | # layout.h 5 | # 6 | # Written by Carter T. Butts 7 | # Last Modified 9/6/10 8 | # Licensed under the GNU General Public License version 2 (June, 1991) 9 | # or greater 10 | # 11 | # Part of the R/network package 12 | # 13 | # This file contains headers for layout.c. 14 | # 15 | ###################################################################### 16 | */ 17 | #ifndef LAYOUT_H 18 | #define LAYOUT_H 19 | 20 | /*DECLARATIONS/INCLUSIONS---------------------------------------------------*/ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "utils.h" 28 | 29 | /*Simple list structures to be used for temporary storage of vertex sets.*/ 30 | typedef struct vlisttype{ 31 | long int v; 32 | struct vlisttype *next; 33 | } vlist; 34 | 35 | typedef struct vcelltype{ 36 | int id; 37 | double count,xm,ym; 38 | struct vlisttype *memb; 39 | struct vcelltype *next; 40 | } vcell; 41 | 42 | 43 | /*R-CALLABLE ROUTINES-------------------------------------------------------*/ 44 | 45 | void network_layout_fruchtermanreingold_R(double *d, double *pn, double *pm, 46 | int *pniter, double *pmaxdelta, double *pvolume, double *pcoolexp, double 47 | *prepulserad, int *pncell, double *pcjit, double *pcppr, double *pcpcr, double 48 | *pcccr, double *x, double *y); 49 | 50 | void network_layout_kamadakawai_R(int *d, double *pn, int *pniter, 51 | double *elen, double *pinitemp, double *pcoolexp, double *pkkconst, 52 | double *psigma, double *x, double *y); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | ###################################################################### 3 | # 4 | # utils.h 5 | # 6 | # Written by Carter T. Butts 7 | # Last Modified 08/20/13 8 | # Licensed under the GNU General Public License version 2 (June, 1991) 9 | # or greater 10 | # 11 | # Part of the R/network package 12 | # 13 | # This file contains headers for utils.c. 14 | # 15 | ###################################################################### 16 | */ 17 | #ifndef UTILS_H 18 | #define UTILS_H 19 | 20 | /*DECLARATIONS/INCLUSIONS---------------------------------------------------*/ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #define MIN(a,b) ((a)<(b) ? (a) : (b)) 33 | #define MAX(a,b) ((a)<(b) ? (b) : (a)) 34 | 35 | 36 | /*LIST ACCESS/MODIFICATION ROUTINES-----------------------------------------*/ 37 | 38 | SEXP deleteListElement(SEXP list, const char *str); 39 | 40 | SEXP getListElement(SEXP list, const char *str); 41 | 42 | SEXP setListElement(SEXP list, const char *str, SEXP elem); 43 | 44 | SEXP enlargeList(SEXP list, int n); 45 | 46 | SEXP contractList(SEXP list, int n); 47 | 48 | SEXP concatList(int nel, int names, ...); 49 | 50 | SEXP permuteList(SEXP list, SEXP ord); 51 | 52 | 53 | /*VECTOR COMPARISON/TEST ROUTINES-------------------------------------------*/ 54 | 55 | int vecAnyNA(SEXP a); 56 | 57 | int vecEq(SEXP a, SEXP b); 58 | 59 | int vecIsIn(double a, SEXP b); 60 | 61 | double vecMax(SEXP a); 62 | 63 | double vecMin(SEXP a); 64 | 65 | 66 | /*VECTOR MODIFICATION ROUTINES----------------------------------------------*/ 67 | 68 | SEXP vecAppend(SEXP a, SEXP b); 69 | 70 | SEXP vecRemove(SEXP v, double e); 71 | 72 | SEXP vecUnion(SEXP a, SEXP b); 73 | 74 | SEXP vecUnique(SEXP a); 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /tests/benchmarks: -------------------------------------------------------------------------------- 1 | "elapsed" 2 | "init" 0.947000000000116 3 | "setv" 0.266000000000076 4 | "getv" 0.346000000000004 5 | "listv" 0.130999999999858 6 | "adde" 1.29500000000007 7 | "sete" 3.89800000000014 8 | "gete" 0.196000000000367 9 | "liste" 0.240999999999985 10 | "addmoree" 2.10499999999956 11 | "addmorev" 1.60500000000002 12 | -------------------------------------------------------------------------------- /tests/general.tests2.R: -------------------------------------------------------------------------------- 1 | #Set to TRUE to run tests 2 | if(FALSE){ 3 | 4 | # additional tests of misc network functionality split off from general.tests.R to avoid speed warnings 5 | library(network) 6 | 7 | # ----- check memory saftey with a big assignment --- 8 | net<-network.initialize(100000) 9 | net<-add.edges(net,1:99999,2:100000) 10 | set.edge.attribute(net,'LETTERS',LETTERS) 11 | 12 | # --- tests for get.induced.subgraph additions -- 13 | data(emon) 14 | # extract the network of responders in MtStHelens network with interaction Frequency of 4 15 | subG4<-get.inducedSubgraph(emon$MtStHelens,eid=which(emon$MtStHelens%e%'Frequency'==4)) 16 | if(network.size(subG4)!=24){ 17 | stop('wrong size eid induced subgraph') 18 | } 19 | 20 | if (any(subG4%e%'Frequency'!=4)){ 21 | stop('bad edges in eid induced subgraph') 22 | } 23 | 24 | # checks for error conditions 25 | # can't specify eid with v or alter 26 | # get.inducedSubgraph(v=1:2,emon$MtStHelens,eid=which(emon$MtStHelens%e%'Frequency'==4)) 27 | # get.inducedSubgraph(alter=1:2,emon$MtStHelens,eid=which(emon$MtStHelens%e%'Frequency'==4)) 28 | # get.inducedSubgraph(emon$MtStHelens,eid=200:300) 29 | 30 | 31 | # ---- tests for specific bugs/edgecases ----- 32 | 33 | # ticket #180 (used to throw error if no edges exist) 34 | set.edge.attribute(network.initialize(3),"test","a") 35 | 36 | # check for network of zero size --used to give error ticket #255 37 | set.vertex.attribute(network.initialize(0),'foo','bar') 38 | 39 | 40 | # check for is.na.network problems #619 41 | x2<-network.initialize(3) 42 | x2[1,2]<-NA 43 | if(is.na.network(x2)[1,2]!=1){ 44 | stop('problem iwth is.na.netowrk') 45 | } 46 | 47 | # check for na problems in which.matrix.type #926 48 | mat <- matrix(rbinom(200, 1, 0.2), nrow = 20) 49 | naIndices <- sample(1:200, 20) 50 | mat[naIndices] <- NA 51 | nw <- network(mat) 52 | 53 | # ---- check for undirected loops getID cases #327 #609 ----- 54 | net<-network.initialize(2,loops=TRUE,directed=FALSE) 55 | net[1,1]<-1 56 | net[1,2]<-1 57 | net[2,2]<-1 58 | if(get.edgeIDs(net,v=1,alter=1)!=1){ 59 | stop("problem with get.edgeIDs on undirected network with loops") 60 | } 61 | if(get.edgeIDs(net,v=2,alter=2)!=3){ 62 | stop("problem with get.edgeIDs on undirected network with loops") 63 | } 64 | 65 | net<-network.initialize(2,loops=TRUE,directed=FALSE) 66 | net[1,2]<-1 67 | if(length(get.edgeIDs(net,v=2,alter=2))>0){ 68 | stop("problem with get.edgeIDs on undirected network with loops") 69 | } 70 | 71 | # check for problem with as.network.edgelist with zero edges #1138 72 | result1 <- as.matrix.network.edgelist(network.initialize(5),as.sna.edgelist = TRUE) 73 | if (nrow(result1) != 0){ 74 | stop('as.matrix.network.edgelist did not return correct value for net with zero edges') 75 | } 76 | result1a <- tibble::as_tibble(network.initialize(5)) 77 | if (nrow(result1a) != 0){ 78 | stop('as_tibble.network did not return correct value for net with zero edges') 79 | } 80 | result2<-as.matrix.network.adjacency(network.initialize(5)) 81 | if(nrow(result2) != 5 & ncol(result2) != 5){ 82 | stop('as.matrix.network.adjacency did not return matrix with correct dimensions') 83 | } 84 | result3<-as.matrix.network.adjacency(network.initialize(0)) 85 | if(nrow(result3) != 0 & ncol(result3) != 0){ 86 | stop('as.matrix.network.adjacency did not return matrix with correct dimensions') 87 | } 88 | result4<-as.matrix.network.incidence(network.initialize(5)) 89 | if(nrow(result4) != 5 & ncol(result4) != 0){ 90 | stop('as.matrix.network.incidence did not return matrix with correct dimensions') 91 | } 92 | result5<-as.matrix.network.incidence(network.initialize(0)) 93 | if(nrow(result5) != 0 & ncol(result5) != 0){ 94 | stop('as.matrix.network.incidence did not return matrix with correct dimensions') 95 | } 96 | 97 | #End test 98 | } 99 | -------------------------------------------------------------------------------- /tests/list.attribute.tests.R: -------------------------------------------------------------------------------- 1 | #Set to TRUE to run tests 2 | if(FALSE){ 3 | 4 | require(network) 5 | 6 | # --------- test list.vertex.attributes --- 7 | 8 | net<-network.initialize(3) 9 | 10 | list.vertex.attributes(net) 11 | 12 | if(!all(list.vertex.attributes(net)==c('na','vertex.names'))){ 13 | stop('list.vertex.attribute did not report default attributes corrrectly') 14 | } 15 | 16 | set.vertex.attribute(net,'letters',c("a","b","c")) 17 | 18 | if(!all(list.vertex.attributes(net)==c('letters','na','vertex.names'))){ 19 | stop('list.vertex.attribute did not report added attributes corrrectly') 20 | } 21 | 22 | 23 | # ----- test list.edge.attributes ---- 24 | 25 | net<-network.initialize(3) 26 | if(length(list.edge.attributes(net))!=0){ 27 | stop("list.edge.attributes did not return empty list for network with no edges") 28 | } 29 | 30 | add.edges(net,1,2) 31 | add.edges(net,2,3) 32 | if(list.edge.attributes(net)!='na'){ 33 | stop("list.edge.attributes did not return 'na' for network with only edges") 34 | } 35 | 36 | set.edge.attribute(net,'letter',c("a","b")) 37 | if(!all(list.edge.attributes(net)==c('letter','na'))){ 38 | stop("list.edge.attributes did not return attribute names for network with edges") 39 | } 40 | 41 | delete.edges(net,eid=1) 42 | if(!all(list.edge.attributes(net)==c('letter','na'))){ 43 | stop("list.edge.attributes did not return attribute names for network deleted edge") 44 | } 45 | 46 | # ---- test list.network.attributes ---- 47 | net<-network.initialize(3) 48 | if(!all(list.network.attributes(net)==c("bipartite", "directed", "hyper","loops","mnext", "multiple","n" ))){ 49 | stop("list.network.attributes returned unexpected values for default attributes of a network") 50 | } 51 | 52 | set.network.attribute(net,'letter',"a") 53 | if(!all(list.network.attributes(net)==c("bipartite", "directed", "hyper","letter","loops","mnext", "multiple","n" ))){ 54 | stop("list.network.attributes returned unexpected values for network with attribute added") 55 | } 56 | 57 | # ----- tests for printing function for edges cases ------ 58 | net<-network.initialize(100) 59 | net%n%'a_matrix'<-matrix(1:100,nrow=10,ncol=10) 60 | net%n%'a_null'<-NULL 61 | net%n%'a_list'<-list(part1=list(c("A","B")),part2=list("c")) 62 | net%n%'a_desc_vec'<-numeric(rep(100,1)) 63 | net%n%'a_net'<-network.initialize(5) 64 | print.network(net) 65 | 66 | #End tests 67 | } 68 | -------------------------------------------------------------------------------- /tests/network.access.test.R: -------------------------------------------------------------------------------- 1 | #Set to TRUE to run tests 2 | if(FALSE){ 3 | 4 | library(network) 5 | 6 | binet = network.initialize(10, bipartite = 6) 7 | set.vertex.attribute(binet, 'myval', paste('b1', 1:6), v=1:6) 8 | set.vertex.attribute(binet, 'myval', paste('b2', 1:4), v=7:10) 9 | 10 | check <- vector() 11 | check[1] <- all(get.vertex.attribute(binet, 'myval') == c("b1 1", "b1 2", "b1 3", "b1 4", "b1 5", "b1 6", "b2 1", "b2 2", "b2 3" ,"b2 4")) 12 | 13 | # check for distinction between bipartite=FALSE and bipartite=0 14 | testA<-network.initialize(3,bipartite=0) 15 | if(!is.bipartite(testA)){ 16 | stop('failed test of is.bipartite for bipartite=0') 17 | } 18 | 19 | testB<-network.initialize(3,bipartite=FALSE) 20 | if(is.bipartite(testB)){ 21 | stop('failed test of is.bipartite for bipartite=FALSE') 22 | } 23 | 24 | testC<-network.initialize(3,bipartite=TRUE) 25 | if(!is.bipartite(testC)){ 26 | stop('failed test of is.bipartite for bipartite=TRUE') 27 | } 28 | 29 | if(!is.bipartite(binet)){ 30 | stop('failed test of is.bipartite for bipartite=6') 31 | } 32 | 33 | # add vertices to bipartite graphs 34 | g = binet; add.vertices(g, 5, last.mode=F) 35 | check[2] <- network.size(g) == 15 36 | check[3] <- get.network.attribute(g, 'bipartite') == 11 37 | check[4] <- identical(get.vertex.attribute(g, 'myval'), 38 | c("b1 1", "b1 2", "b1 3", "b1 4", "b1 5", "b1 6", NA,NA,NA,NA,NA,"b2 1","b2 2","b2 3","b2 4")) 39 | 40 | test<-network.initialize(3,bipartite=0) 41 | test%v%'letters'<-LETTERS[1:3] 42 | add.vertices(test,nv=1,last.mode=FALSE) 43 | if(!identical(test%v%'letters',c(NA,"A","B","C"))){ 44 | stop("Error adding vertices to first mode of network with biparite=0") 45 | } 46 | 47 | test<-network.initialize(3,bipartite=0) 48 | test%v%'letters'<-LETTERS[1:3] 49 | add.vertices(test,nv=1,last.mode=TRUE) 50 | if(!identical(test%v%'letters',c("A","B","C",NA))){ 51 | stop("Error adding vertices to last mode of network with biparite=0") 52 | } 53 | 54 | 55 | g = binet 56 | add.vertices(g, 5, last.mode=T) 57 | check[5] <- network.size(g) == 15 58 | check[6] <- get.network.attribute(g, 'bipartite') == 6 59 | check[7] <- identical(get.vertex.attribute(g, 'myval'), 60 | c("b1 1", "b1 2", "b1 3", "b1 4", "b1 5", "b1 6","b2 1","b2 2","b2 3","b2 4", NA,NA,NA,NA,NA)) 61 | 62 | # replacement operators should always replace 63 | y <- network.initialize(4,dir=FALSE) # This network can have at most 1 edge. 64 | y[1,2] <- NA # Assign NA to (1,2) 65 | y[1,2] <- NA 66 | check[8] <- network.edgecount(y) == 0 67 | check[9] <- network.edgecount(y, na.omit=F) == 1 68 | 69 | y[,] <- 1 70 | check[10] <- network.edgecount(y) == 6 71 | y[,] <- NA 72 | check[11] <- network.edgecount(y) == 0 73 | check[12] <- network.edgecount(y, na.omit=F) == 6 74 | y[,] <- 0 75 | check[13] <- network.edgecount(y, na.omit=F) == 0 76 | 77 | 78 | # ------ test valid.eids function 79 | net<-network.initialize(4) 80 | net[,]<-1 81 | delete.edges(net,eid=4:6) 82 | if(!all(valid.eids(net)==c(1,2,3,7,8,9,10,11,12))){ 83 | stop('valid.eids did not return correct ids for non-null elements of network') 84 | } 85 | 86 | #If everything worked, check is TRUE 87 | if(!all(check)){ #Should be TRUE 88 | stop(paste("network package test failed on test(s):",which(!check))) 89 | } 90 | 91 | #End tests 92 | } 93 | -------------------------------------------------------------------------------- /tests/pathological.tests.R: -------------------------------------------------------------------------------- 1 | #Set to TRUE to run tests 2 | if(FALSE){ 3 | 4 | library(network) 5 | if (require(statnet.common,quietly=TRUE)){ 6 | 7 | opttest({ 8 | gctorture(TRUE) 9 | n <- 10 10 | test <- network.initialize(n) 11 | for (i in 1:(n-1)){ 12 | for (j in (i+1):n){ 13 | cat(i,j,'\n') 14 | get.inducedSubgraph(test,v=i:j) 15 | } 16 | } 17 | gctorture(FALSE) 18 | },'Ticket #180 Test 1','NETWORK_pathology_TESTS') 19 | 20 | opttest({ 21 | gctorture(TRUE) 22 | test <- network.initialize(10) 23 | delete.vertices(test,5) 24 | gctorture(FALSE) 25 | },'Ticket #180 Test 2','NETWORK_pathology_TESTS') 26 | 27 | opttest({ 28 | x <- network.initialize(10) 29 | x[,] <- 1 30 | try(set.edge.value(x,'foo',matrix('bar',5,5))) 31 | },'Ticket #827','NETWORK_pathology_TESTS') 32 | 33 | } 34 | 35 | #End tests 36 | } 37 | -------------------------------------------------------------------------------- /tests/plotflo.R: -------------------------------------------------------------------------------- 1 | #Set to TRUE to run tests 2 | if(FALSE){ 3 | 4 | # 5 | # load the library 6 | # 7 | library(network) 8 | # 9 | # attach the sociomatrix for the Florentine marriage data 10 | # This is not yet a graph object. 11 | # 12 | data(flo) 13 | # 14 | # print out the sociomatrix for the Florentine marriage data 15 | # 16 | flo 17 | # 18 | # Create a network object out of the adjacency matrix and print it out 19 | # 20 | nflo <- network(flo,directed=FALSE) 21 | nflo 22 | # 23 | # print out the sociomatrix for the Florentine marriage data 24 | # 25 | print(nflo,matrix.type="adjacency") 26 | # 27 | # plot the Florentine marriage data 28 | # 29 | plot(nflo) 30 | # 31 | # create a vector indicating the Medici family and add it as a covariate to the 32 | # graph object. 33 | # 34 | nflo <- set.vertex.attribute(nflo,"medici",c(0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0)) 35 | nflo 36 | # 37 | # create a vector indicating the Medici family for the graph 38 | # 39 | medici <- rep("",nrow(flo)) 40 | names(medici) <- dimnames(flo)[[1]] 41 | medici[names(medici)=="Medici"] <- "Medici" 42 | # 43 | # plot the marriage data, highlighting the Medici family 44 | # 45 | plot(nflo,vertex.col=1+get.vertex.attribute(nflo,"medici")) 46 | 47 | # plot the emon St. Helens network, with edge widths proportional 48 | # to 'Frequency', and edges labeled by their id 49 | data(emon) 50 | par(mar=c(0,0,0,0)) 51 | plot(emon[[5]],edge.label=TRUE,edge.label.cex=0.6, 52 | edge.col='gray',edge.lwd=(emon[[5]]%e%'Frequency')*2) 53 | 54 | #End tests 55 | } 56 | -------------------------------------------------------------------------------- /tests/speedTests.R: -------------------------------------------------------------------------------- 1 | #Set to TRUE to run tests 2 | if(FALSE){ 3 | 4 | # some really basic speed checks to help us know if we make changes that massively degrade performance 5 | require(network) 6 | 7 | init<-system.time(net<-network.initialize(100000))[3] 8 | setv<-system.time(set.vertex.attribute(net,"foo","bar"))[3] 9 | getv<-system.time(get.vertex.attribute(net,"foo"))[3] 10 | listv<-system.time(list.vertex.attributes(net))[3] 11 | adde<-system.time(add.edges(net,tail=1:99999,head=2:100000))[3] 12 | sete<-system.time(set.edge.attribute(net,"foo","bar"))[3] 13 | gete<-system.time(get.edge.attribute(net,"foo"))[3] 14 | liste<-system.time(list.edge.attributes(net))[3] 15 | addmoree<-system.time(add.edge(net,100000,1))[3] 16 | addmorev<-system.time(add.vertices(net,1))[3] 17 | 18 | 19 | # optionally compare to benchmarks saved in test folder to see if things have changed 20 | # benchmarks<-rbind(init,setv,getv,listv,adde,sete,gete,liste,addmoree,addmorev) 21 | # oldmarks<-read.table(file.choose(),header=TRUE,colClasses=c('character','numeric')) 22 | # all.equal(oldmarks[,1],benchmarks[,1],check.attributes=FALSE) 23 | 24 | # optionally save out benchmarks to test directory 25 | # write.table(benchmarks,file=file.choose()) 26 | 27 | # some absolute thresholds 28 | 29 | if(init>5){ 30 | stop("initializing network for large number of vertices took much longer than expected") 31 | } 32 | 33 | if(setv>5){ 34 | stop("set.vertex.attribute for large number of vertices took much longer than expected") 35 | } 36 | 37 | if(getv>5){ 38 | stop("get.vertex.attribute for large number of vertices took much longer than expected") 39 | } 40 | 41 | if(listv>1){ 42 | stop("list.vertex.attributes for large number of vertices took much longer than expected") 43 | } 44 | 45 | if(adde>5){ 46 | stop("add.edges for a large number of edges took much longer than expected") 47 | } 48 | 49 | if(sete>10){ 50 | stop("set.edge.attribute for a large number of edges took much longer than expected") 51 | } 52 | 53 | if(gete>1){ 54 | stop("get.edge.attribute for a large number of edges took much longer than expected") 55 | } 56 | 57 | if(liste>1){ 58 | stop("list.edge.attribute for a large number of edges took much longer than expected") 59 | } 60 | 61 | if(addmoree>5){ 62 | stop("add.edge for a network with a large number of edges took much longer than expected") 63 | } 64 | 65 | if(addmorev>5){ 66 | stop("add.vertices for a network with large number of vertices took longer than expected") 67 | } 68 | 69 | #End tests 70 | } 71 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(network) 3 | 4 | test_check("network") 5 | -------------------------------------------------------------------------------- /tests/testthat/test-as.edgelist.R: -------------------------------------------------------------------------------- 1 | test<-network.initialize(5) 2 | add.edges(test,5,1) 3 | add.edges(test,1,5) 4 | set.edge.attribute(test,'value',c('a','b')) 5 | set.edge.attribute(test,'weight',10:11) 6 | 7 | expect_equal( 8 | as.matrix.network.edgelist(test), 9 | structure(c(5L, 1L, 1L, 5L), .Dim = c(2L, 2L), n = 5, vnames = 1:5) 10 | ) 11 | # sort order should be different 12 | if(Sys.getenv("_R_CLASS_MATRIX_ARRAY_") == "" & getRversion() < "4.0.0"){ 13 | expect_equal( 14 | as.edgelist(test), 15 | structure(c(1L, 5L, 5L, 1L), .Dim = c(2L, 2L), n = 5, vnames = 1:5, directed = TRUE, bipartite = FALSE, loops = FALSE, class = c("matrix_edgelist", "edgelist","matrix")) 16 | ) 17 | }else{ 18 | expect_equal( 19 | as.edgelist(test), 20 | structure(c(1L, 5L, 5L, 1L), .Dim = c(2L, 2L), n = 5, vnames = 1:5, directed = TRUE, bipartite = FALSE, loops = FALSE, class = c("matrix_edgelist", "edgelist","matrix","array")) 21 | ) 22 | } 23 | 24 | expect_true(is.edgelist(as.edgelist(test))) 25 | 26 | # numeric attribute 27 | expect_equal(as.matrix.network.edgelist(test,attrname='weight'),structure(c(5L, 1L, 1L, 5L, 10L, 11L), .Dim = 2:3, n = 5, vnames = 1:5)) 28 | 29 | # character attribute NOTE makes the matrix character as well 30 | expect_equal(as.matrix.network.edgelist(test,attrname='value'),structure(c('5', '1', '1', '5', 'a', 'b'), .Dim = 2:3, n = 5, vnames = 1:5)) 31 | 32 | # character attribute with tibble output: does not make matrix character 33 | expect_equal(as.edgelist(test,attrname='value', output="tibble"), 34 | structure(list(.tail = c(1L, 5L), .head = c(5L, 1L), 35 | value = c("b", "a")), row.names = c(NA, -2L), 36 | class = c("tibble_edgelist", "edgelist", "tbl_df", "tbl", "data.frame"), 37 | n = 5, vnames = 1:5, directed = TRUE, bipartite = FALSE, loops = FALSE) 38 | ) 39 | 40 | 41 | undir<-network.initialize(5,directed=FALSE) 42 | add.edges(undir,5,1) 43 | # direction will be swapped to tail < head 44 | expect_equal(as.edgelist(undir)[,], c(1,5)) 45 | 46 | # empty network 47 | as.edgelist(network.initialize(0)) 48 | 49 | # deleted edges 50 | deledge<-network.initialize(5) 51 | add.edges(deledge,1:3,2:4) 52 | delete.edges(deledge,2) 53 | if(Sys.getenv("_R_CLASS_MATRIX_ARRAY_")=="" & getRversion() < "4.0.0"){ 54 | expect_equal( 55 | as.edgelist(deledge), 56 | structure(c(1L, 3L, 2L, 4L), .Dim = c(2L, 2L), n = 5, vnames = 1:5, directed = TRUE, bipartite = FALSE, loops = FALSE, class = c("matrix_edgelist", "edgelist", "matrix")) 57 | ) 58 | }else{ 59 | expect_equal( 60 | as.edgelist(deledge), 61 | structure(c(1L, 3L, 2L, 4L), .Dim = c(2L, 2L), n = 5, vnames = 1:5, directed = TRUE, bipartite = FALSE, loops = FALSE, class = c("matrix_edgelist", "edgelist", "matrix", "array")) 62 | ) 63 | } 64 | 65 | nw <- network.initialize(10L, directed = FALSE) 66 | nw[1L,5L] <- 1L 67 | nw[1L,10L] <- 1L 68 | nw %e% "attr" <- c("a","b") 69 | expect_identical(as.edgelist(nw), structure(matrix(c(1L,1L,5L,10L), nrow = 2L), 70 | n = 10L, 71 | vnames = seq_len(10L), 72 | directed = FALSE, 73 | bipartite = FALSE, 74 | loops = FALSE, 75 | class = c("matrix_edgelist", "edgelist", "matrix", "array"))) 76 | 77 | expect_identical(as.edgelist(nw, attrname = "attr"), structure(matrix(c("1","1","5","10","a","b"), nrow = 2L), 78 | n = 10L, 79 | vnames = seq_len(10L), 80 | directed = FALSE, 81 | bipartite = FALSE, 82 | loops = FALSE, 83 | class = c("matrix_edgelist", "edgelist", "matrix", "array"))) 84 | 85 | nw %n% "bipartite" <- 4L 86 | 87 | expect_identical(as.edgelist(nw), structure(matrix(c(1L,1L,5L,10L), nrow = 2L), 88 | n = 10L, 89 | vnames = seq_len(10L), 90 | directed = FALSE, 91 | bipartite = 4L, 92 | loops = FALSE, 93 | class = c("matrix_edgelist", "edgelist", "matrix", "array"))) 94 | 95 | expect_identical(as.edgelist(nw, attrname = "attr"), structure(matrix(c("1","1","5","10","a","b"), nrow = 2L), 96 | n = 10L, 97 | vnames = seq_len(10L), 98 | directed = FALSE, 99 | bipartite = 4L, 100 | loops = FALSE, 101 | class = c("matrix_edgelist", "edgelist", "matrix", "array"))) 102 | -------------------------------------------------------------------------------- /tests/testthat/test-i22-summary-character.R: -------------------------------------------------------------------------------- 1 | td <- data.frame( 2 | lettres = letters[1:10], 3 | values = 1:10, 4 | stringsAsFactors = FALSE 5 | ) 6 | 7 | # Correct output 8 | correct <- 9 | structure( 10 | c( 11 | "Length:10 ", 12 | "Class :character ", 13 | "Mode :character ", 14 | NA, 15 | NA, 16 | NA, 17 | "Min. : 1.00 ", 18 | "1st Qu.: 3.25 ", 19 | "Median : 5.50 ", 20 | "Mean : 5.50 ", 21 | "3rd Qu.: 7.75 ", 22 | "Max. :10.00 " 23 | ), 24 | .Dim = c(6L, 2L), 25 | .Dimnames = list(c("", "", "", "", "", ""), c(" lettres", " values")), 26 | class = "table" 27 | ) 28 | 29 | 30 | actual <- summary(td) 31 | 32 | 33 | expect_identical(actual, correct) 34 | -------------------------------------------------------------------------------- /tests/testthat/test-indexing.R: -------------------------------------------------------------------------------- 1 | test_that("proper error messages for out of bounds indexing (unipartite)",{ 2 | nw <- network.initialize(10) 3 | expect_error(nw[1,100], "subscript out of bounds") 4 | expect_error(nw[1,100] <- 1, "subscript out of bounds") 5 | expect_error(nw[100,1], "subscript out of bounds") 6 | expect_error(nw[100,1] <- 1, "subscript out of bounds") 7 | }) 8 | 9 | test_that("proper error messages (or lack thereof) for out of bounds indexing (bipartite)",{ 10 | nw <- network.initialize(10, bipartite=3, directed=FALSE) 11 | expect_error(nw[1,3], "subscript out of bounds") 12 | expect_error(nw[1,3] <- 1, "subscript out of bounds") 13 | expect_error(nw[4,5], "subscript out of bounds") 14 | expect_error(nw[4,5] <- 1, "subscript out of bounds") 15 | 16 | expect_error(nw[4,1], NA) 17 | expect_error(nw[5,3], NA) 18 | }) 19 | 20 | test_that("wildcard assignment (bipartite)",{ 21 | nw <- network.initialize(10, bipartite=3, directed=FALSE) 22 | nw[1,] <- 1 23 | expect_equal(network.edgecount(nw), 7) # 7 24 | 25 | nw[,4] <- 1 26 | expect_equal(network.edgecount(nw), 9) # 7 + 3 - 1 27 | 28 | nw[,] <- 1 29 | expect_equal(network.edgecount(nw), 21) # 3*7 30 | }) 31 | -------------------------------------------------------------------------------- /tests/testthat/test-misc_tests.R: -------------------------------------------------------------------------------- 1 | # tests for misc R functions 2 | 3 | test<-network.initialize(5) 4 | test[1,2]<-1 5 | expect_equal(has.edges(test), c(TRUE,TRUE,FALSE,FALSE,FALSE)) 6 | expect_equal(has.edges(test,v=2:3),c(TRUE,FALSE)) 7 | expect_error(has.edges(test,v=10),regexp = 'argument must be a valid vertex id') 8 | expect_equal(length(has.edges(network.initialize(0))),0) 9 | -------------------------------------------------------------------------------- /tests/testthat/test-networks.R: -------------------------------------------------------------------------------- 1 | # ----- checks for network edgecount ------ 2 | 3 | test<-network.initialize(4) 4 | # directed 5 | expect_equal(network.dyadcount(test),12) 6 | # undirected 7 | test%n%'directed'<-FALSE 8 | expect_equal(network.dyadcount(test),6) 9 | 10 | # loops allowed 11 | test%n%'loops'<-TRUE 12 | #undirected 13 | expect_equal(network.dyadcount(test),10) 14 | # directed 15 | test%n%'directed'<-TRUE 16 | expect_equal(network.dyadcount(test),16) 17 | 18 | # directed bipartite 19 | test%n%'loops'<-FALSE 20 | test%n%'bipartite'<-1 21 | expect_equal(network.dyadcount(test),6) 22 | 23 | # undirected bipartite 24 | test%n%'directed'<-FALSE 25 | expect_equal(network.dyadcount(test),3) 26 | 27 | # NA values 28 | test[1,2]<-NA 29 | expect_equal(network.dyadcount(test,na.omit = TRUE),2) 30 | 31 | 32 | # ----- checks for dyads eids ----- 33 | 34 | data(emon) 35 | el<-as.matrix.network.edgelist(emon[[1]]) 36 | expect_equal(get.dyads.eids(emon[[1]],el[,1],el[,2]),as.list(1:83)) 37 | expect_equal(get.dyads.eids(emon[[1]],el[5:10,1],el[5:10,2]),as.list(5:10)) 38 | expect_error(get.dyads.eids(emon[[1]],1,2:3),regexp = 'heads and tails vectors must be the same length') 39 | expect_error(get.dyads.eids(network.initialize(0),1,2),regexp = 'invalid vertex id in heads or tails vector') 40 | 41 | mult<-network.initialize(5,multiple=TRUE) 42 | add.edges(mult,1,2) 43 | add.edges(mult,1,2) 44 | expect_warning(expect_true(is.na(get.dyads.eids(mult,1,2)[[1]])),regexp = 'multiple edge ids for dyad') 45 | 46 | expect_equal(get.dyads.eids(network.initialize(0),numeric(0),numeric(0)), list()) 47 | expect_equal(get.dyads.eids(network.initialize(5),tails=1:2,heads=3:4),list(numeric(0),numeric(0))) 48 | 49 | # check oposite matching for undirected nets 50 | undir<-network.initialize(3,directed=FALSE) 51 | undir[1,2]<-1 52 | expect_equal(get.dyads.eids(undir,2,1),list(1)) 53 | expect_equal(get.dyads.eids(undir,1,2),list(1)) 54 | 55 | 56 | undir%n%'directed'<-TRUE 57 | expect_equal(get.dyads.eids(undir,2,1),list(integer(0))) 58 | expect_equal(get.dyads.eids(undir,1,2),list(1)) 59 | 60 | expect_equal(get.dyads.eids(undir,2,1,neighborhood='in'),list(1)) 61 | expect_equal(get.dyads.eids(undir,1,2,neighborhood='in'),list(integer(0))) 62 | 63 | nw <- network.initialize(10, directed = FALSE) 64 | el <- matrix(c(1,2,3,5,2,9,9,10,6,7),ncol=2,byrow=TRUE) 65 | nw[el]<-1 66 | expect_identical(get.dyads.eids(nw, el[,1], el[,2], na.omit = FALSE), as.list(seq_len(NROW(el)))) 67 | expect_identical(get.dyads.eids(nw, el[,1], el[,2], na.omit = TRUE), as.list(seq_len(NROW(el)))) 68 | nw[el[2,1],el[2,2]] <- NA 69 | nw[el[5,1],el[5,2]] <- NA 70 | expect_identical(get.dyads.eids(nw, el[,1], el[,2], na.omit = FALSE), as.list(seq_len(NROW(el)))) 71 | expect_identical(get.dyads.eids(nw, el[,1], el[,2], na.omit = TRUE), list(1L, integer(0), 3L, 4L, integer(0))) 72 | delete.edges(nw, 2) 73 | expect_identical(get.dyads.eids(nw, el[,1], el[,2], na.omit = FALSE), list(1L, integer(0), 3L, 4L, 5L)) 74 | expect_identical(get.dyads.eids(nw, el[,1], el[,2], na.omit = TRUE), list(1L, integer(0), 3L, 4L, integer(0))) 75 | delete.edges(nw, 3) 76 | expect_identical(get.dyads.eids(nw, el[,1], el[,2], na.omit = FALSE), list(1L, integer(0), integer(0), 4L, 5L)) 77 | expect_identical(get.dyads.eids(nw, el[,1], el[,2], na.omit = TRUE), list(1L, integer(0), integer(0), 4L, integer(0))) 78 | -------------------------------------------------------------------------------- /tests/testthat/test-plot.R: -------------------------------------------------------------------------------- 1 | # various tests for network plotting functions 2 | # mostly recent functionality added by skyebend 3 | 4 | # Open null device 5 | pdf(file = NULL, onefile = TRUE) 6 | dev_id <- dev.cur() 7 | 8 | # ----- test edge labels ------ 9 | ymat<-matrix(c(0,1,2,3, 0,0,0,0, 1,0,0,0, 0,0,0,0),ncol=4) 10 | ynet<-network(ymat,ignore.eval=FALSE,names.eval='weight') 11 | # don't do anything if no value given 12 | plot(ynet,edge.label.col='blue',edge.label.cex='weight') 13 | # use edge ids is if edge.label=TRUE 14 | plot(ynet,edge.label=TRUE) 15 | 16 | plot(ynet,edge.label='weight',edge.label.col='blue',edge.label.cex='weight') 17 | 18 | # labels for curved edges 19 | plot(ynet,edge.label='weight',edge.label.col='blue',edge.label.cex='weight',usecurve=TRUE) 20 | plot(ynet,edge.label='weight',edge.label.col='blue',edge.label.cex='weight',usecurve=TRUE,edge.curve=0.5) 21 | 22 | data(emon) 23 | par(mar=c(0,0,0,0)) 24 | plot(emon[[5]],edge.label=TRUE,edge.label.cex=0.6,edge.col='gray',edge.lwd=(emon[[5]]%e%'Frequency')*2) 25 | 26 | # test for labeling network with no edges #521 27 | plot(network.initialize(1),edge.label=TRUE) 28 | 29 | # test color stuff 30 | 31 | col.list<-c('red','#800000','#80000505',NA) 32 | # test is.color for vector NA processing bug #491 33 | if(!all(is.color(col.list)[1:3] & is.na(is.color(col.list)[4]))){ 34 | stop('is.color did not correctly recognize colors and NA values in a character vector') 35 | } 36 | 37 | col.list<-list('red','#800000','#80000505',NA) 38 | # test is.color for list NA processing bug #491 39 | if(!all(is.color(col.list)[1:3] & is.na(is.color(col.list)[4]))){ 40 | stop('is.color did not correctly recognize colors and NA values in a list') 41 | } 42 | 43 | # ------------ as.color -------- 44 | 45 | expect_equal(as.color(c('a','b','c')),1:3) # character 46 | expect_equal(as.color(1:3),1:3) # numeric 47 | expect_equal(as.color(as.factor(c('a','b','c'))),1:3) # factor 48 | expect_equal(as.color(c('red','green','blue')),c('red','green','blue')) # color name 49 | expect_equal(as.color(c(1,0.5,0)),c("#FFFFFF", "#808080", "#000000"))# real valued (gray) 50 | # transparency/ opacity 51 | expect_equal(as.color(c('red','green','blue'),0.5),c("#FF000080", "#00FF0080", "#0000FF80")) 52 | if(R.Version()$major <= 3) expect_equal(as.color(1:3,0.5),c("#00000080", "#FF000080", "#00CD0080")) else expect_equal(as.color(1:3,0.5),c("#00000080", "#DF536B80", "#61D04F80")) 53 | expect_error(as.color(c('red','green','blue'),1.5),regexp = 'opacity parameter must be a numeric value in the range 0 to 1') 54 | 55 | 56 | # ----- plot fixes ---- 57 | 58 | plot(network.initialize(5),vertex.lwd=c(1,2,3,5,10)) 59 | 60 | # test for expansion of label attribute name bug #785 61 | # this should produce a plot with vertices labeled A to E, instead 62 | # used to plot single vertex is labeled with "Label' 63 | test<-network.initialize(5) 64 | set.vertex.attribute(test,'Label',LETTERS[1:5]) 65 | plot(test,label='Label') 66 | 67 | # replicates non-matching label name 68 | plot(test,label='A') 69 | plot(test,label=1) 70 | 71 | # should error if all values are missing 72 | #set.vertex.attribute(test,'bad',NA,v=1:3) 73 | #plot(test,label='bad') 74 | 75 | # tests for #673 plot.network.default gives error when rendering labels if two connected vertices have the same position 76 | test<-network.initialize(2) 77 | test[1,2]<-1 78 | plot(test,coord=cbind(c(1,1),c(1,1)),jitter=FALSE,displaylabels=TRUE) 79 | 80 | test<-network.initialize(3) 81 | test[1,2:3]<-1 82 | plot(test,coord=cbind(c(1,1,2),c(1,1,2)),jitter=FALSE,displaylabels=TRUE) 83 | 84 | # tests for polygon sizes/sides 85 | plot(network.initialize(7),vertex.sides=c(50,4,3,2,1,0,NA),vertex.cex=40,coord=matrix(0,ncol=7,nrow=7),jitter=F,vertex.col='#CCCCCC00',vertex.border =c('red','green','blue','orange')) 86 | plot(network.initialize(7),vertex.sides=c(50,4,3,2,1,0,NA),vertex.cex=0) 87 | plot(network.initialize(7),vertex.sides=c(50,4,3,2,1,0,NA),vertex.cex=NA) 88 | 89 | # close the device 90 | dev.off(which = dev_id) 91 | -------------------------------------------------------------------------------- /tests/vignette.R: -------------------------------------------------------------------------------- 1 | require("network") 2 | set.seed(1702) 3 | 4 | results = NULL 5 | 6 | data("flo") 7 | data("emon") 8 | 9 | net <- network.initialize(5) 10 | net 11 | 12 | nmat <- matrix(rbinom(25, 1, 0.5), nr = 5, nc = 5) 13 | net <- network(nmat, loops = TRUE) 14 | net 15 | 16 | summary(net) 17 | results[1] = all(nmat == net[,]) 18 | 19 | net <- as.network(nmat, loops = TRUE) 20 | results[2] = all(nmat == net[,]) 21 | 22 | nflo <- network(flo, directed = FALSE) 23 | nflo 24 | 25 | results[3] = all(nflo[9,] == c(1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1)) 26 | results[4] = nflo[9,1] == 1 27 | results[5] = nflo[9,4] == 0 28 | results[6] = is.adjacent(nflo, 9, 1) == TRUE 29 | results[7] = is.adjacent(nflo, 9, 4) == FALSE 30 | 31 | results[8] = network.size(nflo) == 16 32 | results[9] = network.edgecount(nflo) == 20 33 | results[10] = network.density(nflo) == 1/6 34 | results[11] = has.loops(nflo) == FALSE 35 | results[12] = is.bipartite(nflo) == FALSE 36 | results[13] = is.directed(nflo) == FALSE 37 | results[14] = is.hyper(nflo) == FALSE 38 | results[15] = is.multiplex(nflo) == FALSE 39 | 40 | as.sociomatrix(nflo) 41 | 42 | results[16] = all(nflo[,] == as.sociomatrix(nflo)) 43 | results[17] = all(as.matrix(nflo) == as.sociomatrix(nflo)) 44 | as.matrix(nflo,matrix.type = "edgelist") 45 | 46 | net <- network.initialize(5, loops = TRUE) 47 | net[nmat>0] <- 1 48 | results[18] = all(nmat == net[,]) 49 | 50 | net[,] <- 0 51 | net[,] <- nmat 52 | results[19] = all(nmat == net[,]) 53 | 54 | net[,] <- 0 55 | for(i in 1:5) 56 | for(j in 1:5) 57 | if(nmat[i,j]) 58 | net[i,j] <- 1 59 | results[20] = all(nmat == net[,]) 60 | 61 | net[,] <- 0 62 | add.edges(net, row(nmat)[nmat>0], col(nmat)[nmat>0]) 63 | results[21] = all(nmat == net[,]) 64 | 65 | net[,] <- as.numeric(nmat[,]) 66 | results[22] = all(nmat == net[,]) 67 | 68 | net <- network.initialize(5) 69 | add.edge(net, 2, 3) 70 | net[,] 71 | results[23] = net[2,3] == 1 72 | 73 | add.edges(net, c(3, 5), c(4, 4)) 74 | net[,] 75 | results[24] = (net[3,4] == 1 && net[5,4] == 1) 76 | 77 | net[,2] <- 1 78 | net[,] 79 | results[25] = net[2,2] == 0 80 | 81 | delete.vertices(net, 4) 82 | results[26] = all(net[,] == matrix(c(0,1,0,0,0,0,1,0,0,1,0,0,0,1,0,0), byrow=T, nrow=4)) 83 | 84 | add.vertices(net, 2) 85 | net[,] 86 | 87 | get.edges(net, 1) 88 | get.edges(net, 2, neighborhood = "in") 89 | get.edges(net, 1, alter = 2) 90 | 91 | results[27] = get.edgeIDs(net, 1) == 4 92 | results[28] = all(get.edgeIDs(net, 2, neighborhood = "in") == c(7, 5, 4)) 93 | results[29] = get.edgeIDs(net, 1, alter = 2) == 4 94 | 95 | results[30] = get.neighborhood(net, 1) == 2 96 | results[31] = all(get.neighborhood(net, 2, type = "in") == c(4, 3, 1)) 97 | 98 | net[2,3] <- 0 99 | results[32] = net[2,3] == 0 100 | 101 | delete.edges(net, get.edgeIDs(net, 2, neighborhood = "in")) 102 | results[33] = all(net[,] == matrix(0, 6,6)) 103 | 104 | net <- network.initialize(5) 105 | set.network.attribute(net, "boo", 1:10) 106 | net %n% "hoo" <- letters[1:7] 107 | 108 | results[34] = 'boo' %in% list.network.attributes(net) 109 | results[35] = 'hoo' %in% list.network.attributes(net) 110 | 111 | results[36] = all(get.network.attribute(net, "boo") == c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) 112 | results[37] = all(net %n% "hoo" == c("a", "b", "c", "d", "e", "f", "g")) 113 | 114 | delete.network.attribute(net, "boo") 115 | results[38] = 'boo' %in% list.network.attributes(net) == FALSE 116 | 117 | set.vertex.attribute(net, "boo", 1:5) 118 | net %v% "hoo" <- letters[1:5] 119 | results[39] = 'boo' %in% list.vertex.attributes(net) 120 | results[40] = 'hoo' %in% list.vertex.attributes(net) 121 | 122 | results[41] = all(get.vertex.attribute(net, "boo") == 1:5) 123 | results[42] = all(net %v% "hoo" == letters[1:5]) 124 | delete.vertex.attribute(net, "boo") 125 | results[43] = 'boo' %in% list.vertex.attributes(net) == FALSE 126 | 127 | net <- network(nmat) 128 | set.edge.attribute(net, "boo", sum(nmat):1) 129 | set.edge.value(net, "hoo", matrix(1:25, 5, 5)) 130 | net %e% "woo" <- matrix(rnorm(25), 5, 5) 131 | net[,, names.eval = "zoo"] <- nmat * 6 132 | results[44] = 'boo' %in% list.edge.attributes(net) 133 | results[45] = 'hoo' %in% list.edge.attributes(net) 134 | 135 | results[46] = all(get.edge.attribute(get.edges(net, 1), "boo") == c(3,7)) 136 | results[47] = all(get.edge.value(net, "hoo") == c(2, 3, 11, 14, 17, 18, 21)) 137 | net %e% "woo" 138 | as.sociomatrix(net, "zoo") 139 | delete.edge.attribute(net, "boo") 140 | results[48] = 'boo' %in% list.edge.attributes(net) == FALSE 141 | 142 | MtSHloc <- emon$MtStHelens %v% "Location" 143 | MtSHimat <- cbind(MtSHloc %in% c("L", "B"), MtSHloc %in% c("NL", "B")) 144 | MtSHbyloc <- network(MtSHimat, matrix = "incidence", hyper = TRUE, 145 | directed = FALSE, loops = TRUE) 146 | MtSHbyloc %v% "vertex.names" <- emon$MtStHelens %v% "vertex.names" 147 | MtSHbyloc 148 | 149 | plot(nflo, displaylabels = TRUE, boxed.labels = FALSE) 150 | plot(nflo, displaylabels = TRUE, mode = "circle") 151 | plot(emon$MtSi) 152 | 153 | if (!all(results)) { 154 | stop(paste('The following tests in vignette.R failed:', which(results==FALSE))) 155 | } 156 | 157 | -------------------------------------------------------------------------------- /vignettes/networkVignette.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/statnet/network/ffe733f403b625d7eb31ba2e3a0082fa958d7a6b/vignettes/networkVignette.pdf --------------------------------------------------------------------------------