-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomp_vectors.r
executable file
·43 lines (32 loc) · 1 KB
/
comp_vectors.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env Rscript
args = commandArgs(trailingOnly=T)
if (length(args) < 2) {
warning(paste("number of args:",length(args)))
stop("two files are needed as arguments")
}
fp1 <- file.path(args[1])
fp2 <- file.path(args[2])
if (!file.exists(fp1))
stop("file does not exist: ",fp1)
if (!file.exists(fp2))
stop("file does not exist: ",fp2)
q <- scan(fp1,what=character())
d <- scan(fp2,what=character())
print(paste("from",fp1[length(fp1)],"to",fp2[length(fp2)]))
first2second <- setdiff(q,d)
## intersect12 <- intersect(q,d)
print("Difference:")
print(paste("length:",length(first2second)))
print(first2second)
## print("Intersection:")
## print(paste("length:",length(intersect12)))
## print(intersect12)
print(paste("from",fp2[length(fp2)],"to",fp1[length(fp1)]))
second2first <- setdiff(d,q)
intersect21 <- intersect(d,q)
print("Difference:")
print(paste("length:",length(second2first)))
print(second2first)
print("Intersection:")
print(paste("length:",length(intersect21)))
print(intersect21)