• 0

write stdout using write_csv() ...



dear Fellow Coder on Neowin 



im using bash to pipe the gathered data through an Rscript like so:


cat random.csv | Rscript test.R arg >| delete.csv


My aim is to use the R package readr to both read stdin and write stdout. what is aimed:  I found the answer to stdin here.




args  <- commandArgs(trailingOnly = TRUE)

df.in <- read_csv(file("stdin"))

write_csv(df.in, path = stdout())


My investigations gave back the foolowing: 

There is a format_csv function for that in readr. Use this instead of write_csv:




we also can use write.table:


write.table(x, file = "foo.csv", sep = ",", col.names = NA,
        qmethod = "double")



i found the following interesting help page: https://stat.ethz.ch/R-manual/R-devel/library/utils/html/write.table.html 


import requests
from bs4 import BeautifulSoup
import pandas as pd

def Main(urls):
    with requests.Session() as req:
        allin = []
        for url in urls:
            r = req.get(url)
            soup = BeautifulSoup(r.content, 'html.parser')
            target = soup.find(
                "dl", class_="c-description-list c-description-list--striped")
            names = [item.text for item in target.findAll("dt")]
            data = [item.get_text(strip=True) for item in target.findAll("dd")]
        df = pd.DataFrame(allin, columns=names)
        df.to_csv("data.csv", index=False, encoding="utf-8")

urls = ['https://www2.daad.de/deutschland/studienangebote/international-programmes/en/detail/4722/',


the question is. i want to write the results of the parser script to stdout . - i do not want to write it into the data-file.



Link to post
Share on other sites

1 answer to this question

Recommended Posts

This topic is now closed to further replies.
  • Recently Browsing   0 members

    No registered users viewing this page.