Compute specific and intersection elements with R

This is my first posts about R language, my first english post and my first R package: venn.compute, which use case in bioinformatics is compare list of genes.

This R package is intended to compute specific elements in intersections of Venn diagram instead of plot.

  • Custom reader of files to create list of character arrays (such requiered for this package and VennDiagram).
  • Compute specific elements in intersections of Venn diagram in memory or write to files.
  • Plot with VennDiagram.


Use 3 files in tests directory with names primes.txt, even.txt y fibo.txt whose content are primes, even and Fibonacci numbers until 20.


You can install from GitHub as:


Downloading GitHub repo cosmoscalibur/venn.compute@master

formatR (1.6 -> 1.7) [CRAN]

Installing 1 packages: formatR
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done

  checking for file /tmp/RtmpT7UVx3/remotes61d65fec5ae1/cosmoscalibur-venn.compute-6f4fb43/DESCRIPTION ...
  preparing venn.compute’:
  checking DESCRIPTION meta-information
  checking for LF line-endings in source and make files and shell scripts
  checking for empty or unneeded directories
  building venn.compute_1.1.0.tar.gz

If an error about TAR executable is showed (common in Linux with Anaconda, sh: 1: /bin/gtar: not found), you need to setup your TAR path.

Sys.setenv(TAR = "/bin/tar")

How to use

First, load the package.


Lectura de archivos

Read files

This is a custom reader to include multiple files and associate its custom names, returned a named list of character arrays (each element is an element line of the file).

sets <- read.lists_from_files(c(file.path("tests", "primes.txt"),
                                file.path("tests", "even.txt"),
                                file.path("tests", "fibo.txt")),
                              c("primes", "even", "fibo"))
[1] "1"  "2"  "3"  "5"  "7"  "11" "13" "17"

 [1] "0"  "2"  "4"  "6"  "8"  "10" "12" "14" "16" "18"

[1] "1"  "2"  "3"  "5"  "8"  "13"

Compute intersections and specific elements

Now you can compute specific elements of Venn diagram intersections.

  1. '1'
  2. '3'
  3. '5'
  4. '13'
  1. '7'
  2. '11'
  3. '17'
  1. '0'
  2. '4'
  3. '6'
  4. '10'
  5. '12'
  6. '14'
  7. '16'
  8. '18'

If you need to write sets in files, add an output path. Files are written using convention of join sets name with underscore.

venn.compute_specific(sets, output_dir = file.path("tests", "output"))

We can verify written files.

dir(file.path("tests", "output"))
  1. 'even_fibo.txt'
  2. 'even.txt'
  3. 'fibo.txt'
  4. 'primes_even_fibo.txt'
  5. 'primes_even.txt'
  6. 'primes_fibo.txt'
  7. 'primes.txt'

Plot Venn diagram

Finally, if you want to save plot, invoke this function with the same arguments as before (internally using VennDiagram)

venn.compute_plot(sets, output_dir = file.path("tests", "output"))

Now, we have a primes_even_fibo.png file.

Venn diagram generate here with VennDiagram.


Comments powered by Disqus