Ho i seguenti dati (un elenco di pacchetti R analizzati da un file Rmarkdown), che voglio trasformare in un elenco che posso passare a R per installare:
d3heatmap
data.table
ggplot2
htmltools
htmlwidgets
metricsgraphics
networkD3
plotly
reshape2
scales
stringr
Voglio trasformare l'elenco in un elenco del modulo:
'd3heatmap', 'data.table', 'ggplot2', 'htmltools', 'htmlwidgets', 'metricsgraphics', 'networkD3', 'plotly', 'reshape2', 'scales', 'stringr'
Al momento ho una pipeline bash che va dal file raw all'elenco sopra:
grep 'library(' Presentation.Rmd \
| grep -v '#' \
| cut -f2 -d\( \
| tr -d ')' \
| sort | uniq
Voglio aggiungere un passaggio per trasformare le nuove righe nell'elenco separato da virgole. Ho provato ad aggiungere tr '\n' '","', che non riesce. Ho anche provato alcune delle seguenti risposte Stack Overflow, che falliscono anche:
Questo produce library(stringr)))phics)come risultato.
Questo produce ,%come risultato.
Questa risposta (con il -iflag rimosso), produce un output identico all'input.
'o ".