R functions for reading and writing Pajek files without calling another networks package
MotivationMany users who perform network analysis in Pajek simply want to write input files and read output files without calling another networks package. Although several networks packages support reading Pajek files, fewer support writing them. And because the packages assume you want to manipulate the network further using them, they add several more layers of meta-information relevant for the package when reading in the file. The result is slow processing time to simply move files in and out of R.
ScriptsThe script R_Pajek Functions_5May2021.R writes six functions for reading and writing network files (read_net and write_net), partition files (read_clu and write_clu), and vector files (read_vec and write_vec). The functions are written in Base R to avoid package dependency issues.
The logic behind this script is that the user calls the functions using a source statement (e.g., source("/Applications/Pajek64/R_Pajek Functions_5May2021.R"). The functions are written and lists are created that enumerate all the .net, .clu, and .vec files in your work directory. The user can then simply refer to the lists, and avoid writing directory path information.
The script Pajek Functions_User Script_5May2021.R provides a series of use cases and examples. There are examples of reading and writing single files and multiple files. These scripts were tested on PC and OS X machines on medium and large networks, although I have come nowhere near in my tests to Pajek's full range. I expect for networks at Pajek's top end, replacing base R's readLines function with a more efficient reader would be helpful. But, I thought the compatibility issues were worth the tradeoff.
AuthorJonathan H. Morgan, Ph.D.
Fachhochschule Potsdam | University of Applied Sciences
IaF Urbane Zukunft | Institute for Urban Futures
Kiepenheuerallee 5, Haus 4, Raum 3.14
14469 Potsdam, Germany