【问题标题】:How to preserve hyperlinks in r htmltable while writing to a csv/excel file?如何在写入 csv/excel 文件时保留 r htmltable 中的超链接?
【发布时间】:2019-08-18 07:24:16
【问题描述】:

一个 htmltable 中有多个超链接。我希望在写入 csv 文件时保留这些超链接。

我尝试转换为数据框,但在这两种情况下,csv 都扩展了链接。

library(adapr)
library(htmlTable)
library(stringr)

data = data.frame("word"=c('python py', 'java'), 
                  "description"=c('Java is a statically typed and Python py is a dynamically typed',
                                  'java is a programming language'), stringsAsFactors = FALSE)
ll <- as.list(data$word)

data$new <- data$description
for(i in seq_len(nrow(data))) for(j in seq_along(ll)) {
  url <- paste0("http://www.google.com/",ll[[j]])
  url1 <- makeHyperlink(url,ll[[j]])
  url2 <- str_replace(url1,"file:///","")
  data$new[i] <- sub(ll[[j]], url2, data$new[i], ignore.case = TRUE)
}
data1<-htmlTable(data)

我想在 csv/excel 文件中保留 data1$new 中的超链接。

【问题讨论】:

    标签: r html-table hyperlink export-to-csv export-to-excel


    【解决方案1】:

    抱歉,htmlTable 的返回变量不是 data.frame,您得到的是纯文本 HTML 格式字符串。这可能是我最大的设计错误,当时我并没有完全理解 S3 应该如何使用。这种转换应该在print.htmlTable 函数中完成,而htmlTable 只创建一个具有print.htmlTable 中使用的属性的对象。

    【讨论】:

      猜你喜欢
      • 2016-05-18
      • 2017-12-21
      • 1970-01-01
      • 2017-01-20
      • 1970-01-01
      • 1970-01-01
      • 2012-06-29
      • 2022-06-29
      • 1970-01-01
      相关资源
      最近更新 更多