Problems creating hyperlinks on Excel Mac with xlsx r package

69 views Asked by At

I am trying to create an Excel File with r which should include hyperlinks to a website. Everything works fine and can be tested on Windows, but on my Mac it somehow fails... I get the message that

Unable to open "LINK". Cannot locate the internet server or proxy server.

I am not sure if the problem is my excel, my mac or whatever. Could somebody help me to narrow the problem down?

EDIT: I just figured out, google works for example. Updated my example.

Here is a reproducible example

library(xlsx)

df <- data.frame(
  Protein.IDs=c("A0A024QZN2;Q8WXX5;Q2VIL4", 
                "A0A024QZY5;Q13523;B4DZQ5;H0YDJ3;D3DWH5"),
  stringsAsFactors=FALSE
)

df$Uniprot <- 
  sprintf('https://www.uniprot.org/uniprot/?query=%s',
          sapply(strsplit(df$Protein.IDs, ';'), paste, collapse='+OR+'))


df <- rbind(df, c('google link', 'https://google.de')) # EDIT: google works?

excel_wb <- createWorkbook()
sheet <- xlsx::createSheet(excel_wb, sheetName='proteins')
addDataFrame(df, sheet, col.names = TRUE, row.names = FALSE)

rows <- getRows(sheet)
cells <- getCells(rows, colIndex=grep('^Uniprot$', names(df)))

invisible(sapply(cells[-1], function(x) {
  addHyperlink(x, getCellValue(x))
  setCellValue(x, 'Uniprot Link')
}))

rMQanalysis::saveWorkbookMQ(excel_wb, 'uniprottest.xlsx')
1

There are 1 answers

0
drmariod On

For some reason, after a restart of the computer, everything works. Not sure what and if something changed.