====== List titles in subnetworks ====== [[notes:runr|Running Pajek from R]], [[notes:net:titls|List titles]] ===== Function listSubNets ===== Running in Pajek the sequence: * read network * read partition * extract selected subnetwork with a given class number * save subnetwork to a file we get a Pajek log file like this NETBEGIN 1 CLUBEGIN 1 PERBEGIN 1 CLSBEGIN 1 HIEBEGIN 1 VECBEGIN 1 % Reading Network --- C:\Users\batagelj\work\Python\WoS\BM\results\jaccard\Jislands.net N 1 RDN "C:\Users\batagelj\work\Python\WoS\BM\results\jaccard\Jislands.net" (477) % Reading Partition --- C:\Users\batagelj\work\Python\WoS\BM\results\jaccard\Jislands.clu C 1 RDC "C:\Users\batagelj\work\Python\WoS\BM\results\jaccard\Jislands.clu" (477) % Extracting Subnetwork according to Partition N 2 EXT 1 1 [5] 1 (15) % Saving network to file --- C:\Users\batagelj\work\Python\WoS\BM\results\jaccard\Jislands\J5.net N 2 WN "C:\Users\batagelj\work\Python\WoS\BM\results\jaccard\Jislands\J5.net" 0 (15) We transform it into the following "template" NETBEGIN 1 CLUBEGIN 1 PERBEGIN 1 CLSBEGIN 1 HIEBEGIN 1 VECBEGIN 1 N 1 RDN "network" (477) C 1 RDC "partition" (477) N 2 EXT 1 1 [cluster] 1 (15) N 2 WN "subnetwork" 0 (15) EXIT **Important:** The sequence of commands ends with the ''EXIT'' command that exits the Pajek program. The R function ''listSubNets'' for each (non-null) class * substitutes template "parameters" with the class' values and save it on ''Pajek.log'' * apply Pajek on the sequence of commands in ''Pajek.log'' - it extracts a current subnetwork * apply R function ''description'' on the current subnetwork producing a file ''List.csv'' # WoS2Pajek - Extracting subnetworks and listing their titles # V. Batagelj, May 1st, 2017 # ------------------------------------------------------ listSubNets <- function(net,clu,subdir,T){ cat("WoS2Pajek - Extracting subnetworks and listing their titles\n", "V. Batagelj, May 2017\n\n",date(),"\n",sep="") t <- table(read.csv(clu,head=FALSE,skip=1)$V1) if(names(t)[1]=="0") t <- t[2:length(t)] cluA <- paste(getwd(),"/",clu,sep=""); netA <- paste(getwd(),"/",net,sep="") # L <- readLines("getSubnet.txt",n=-1) L <- c("NETBEGIN 1", "CLUBEGIN 1", "PERBEGIN 1", "CLSBEGIN 1", "HIEBEGIN 1", "VECBEGIN 1", "", "N 1 RDN \"network\" (477)", "C 1 RDC \"partition\" (477)", "N 2 EXT 1 1 [cluster] 1 (15)", "N 2 WN \"subnet\" 0 (15)", "EXIT") L <- gsub("partition",cluA,gsub("network",netA,L)) for(i in 1:length(t)) { cl <- names(t)[i]; cat("Subnetwork:",cl,t[i],"\n"); flush.console() sub <- paste("subNet",cl,".net",sep="") subA <- paste(getwd(),subdir,sub,sep="") N <- gsub("subnet",subA,gsub("cluster",cl,L)) writeLines(N,con="Pajek.log") system("C:/programi/pajek/pajek.exe",invisible=TRUE,wait=TRUE) if(!file.exists(subA)) { cat(subA,"*** problems\n"); flush.console(); next } else { csv <- paste(".",subdir,"List",cl,".csv",sep="") d <- description(subA,csv,T) } } } ===== Producing lists ===== [[https://github.com/bavla/biblio/tree/master/Pajek/R|github: description and listSubNets]] We first prepare the right environment: load R functions ''description'' and ''listSubNets'', set the working directory and read in a data frame T the information about works from the file ''titles.csv'' produced by WoS2Pajek: > source("C:/Users/batagelj/work/Python/WoS/peere1/description.R") > source("C:/Users/batagelj/work/Python/WoS/BM/listSubNets.R") > setwd("C:/Users/batagelj/work/Python/WoS/BM/results/jaccard") > T <- read.csv('../../titles.csv',sep=";",colClasses="character"); T$code <- 1 Now we can run the function ''listSubNets'' > listSubNets("Jislands.net","Jislands.clu","/Jislands/",T) WoS2Pajek - Extracting subnetworks and listing their titles V. Batagelj, May 2017 Mon May 01 15:44:26 2017 Subnetwork: 1 18 Subnetwork: 2 32 Subnetwork: 3 21 Subnetwork: 4 74 Subnetwork: 5 15 Subnetwork: 6 15 Subnetwork: 7 54 Subnetwork: 8 20 Subnetwork: 9 22 Subnetwork: 10 20 Subnetwork: 11 22 Subnetwork: 12 23 Subnetwork: 13 45 Subnetwork: 14 26 Subnetwork: 15 70 > We get the corresponding CSV files ''List.csv'' that we can inspect using Excel. {{notes:bm2:pics:list1.png}}