'RInterpreterError: Failed to parse and evaluate line when running R code on Google Colab

I want to run an R code on Google Colaboratory to generate hsa.txt file.

First cell:

%load_ext rpy2.ipython

Second cell:

%%R

install.packages("BiocManager")
BiocManager::install("KEGGREST")
BiocManager::install("EnrichmentBrowser")

library(KEGGREST)
library(EnrichmentBrowser)
library(org.Hs.eg.db)

MRSA252 <- keggList("hsa")
sarpathway <- downloadPathways("hsa")


hsa <- getGenesets(org="hsa", db="kegg", cache=TRUE, return.type="list")
for (i in 1:length(hsa)) {
  t <- unlist(mget(hsa[[i]], envir=org.Hs.egSYMBOL, ifnotfound=NA),use.names=FALSE)
  hsa[[i]] <- t[!is.na(t)]
  # Remove disease-specific pathways
  hsa[[i]] <- hsa[!grep("disease$", hsa)]
}
writeGMT(hsa, gmt.file="hsa.txt")

Traceback:

RInterpreterError: Failed to parse and evaluate line '\ninstall.packages("BiocManager")\nBiocManager::install("KEGGREST")\nBiocManager::install("EnrichmentBrowser")\n\nlibrary(KEGGREST)\nlibrary(EnrichmentBrowser)\nlibrary(org.Hs.eg.db)\n\nMRSA252 <- keggList("hsa")\nsarpathway <- downloadPathways("hsa")\n\n\n\nhsa <- getGenesets(org="hsa", db="kegg", cache=TRUE, return.type="list")\nfor (i in 1:length(hsa)) {\n  t <- unlist(mget(hsa[[i]], envir=org.Hs.egSYMBOL, ifnotfound=NA),use.names=FALSE)\n  hsa[[i]] <- t[!is.na(t)]\n  # Remove disease-specific pathways\n  hsa[[i]] <- hsa[!grep("disease$", hsa)]\n}\nwriteGMT(hsa, gmt.file="hsa.txt")'.
R error message: 'Error in .getUrl(url, .textParser) : Forbidden (HTTP 403).'


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source