11.2.5: How to Incorporate Data Files in Your Code Blocks- For R

Construction Guide for LibreTexts 2e · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    Read aloud

    How

    Speed: 1×
    Light up
    Highlight

    Symbols: Mulberry Symbols, © 2018–2026 Steve Lee, CC BY-SA 4.0 (licence, the set), the site's own copies.

    From LibreTexts, under CC BY-SA 4.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    11.2.5: How to Incorporate Data Files in Your Code Blocks- For R

    There are a number of ways data files and can be incorporated into code blocks. However, ensure that you have already followed the steps in the introduction to the CKEditor Binder Plugin Tutorial here.

    Method 1: Using read.csv

    the url for the file can be saved to a variable or be added in all at once as shown below.

    x <- read.csv(url("https://chem.libretexts.org/@api/deki/files/265970/auto-mpg.data"), sep = '\t', head = FALSE)
    print(x)
    
    

    Keep in mind that larger data files will take longer to load.

    Method 2: Using wget or curl through download.file

    Another option to load in a data file is using wget or curl through the download.file function. An example code block is shown below, replace your url with the one in the example. For more information about the download.file function visit this link.

    url <- "https://chem.libretexts.org/@api/deki/files/265970/auto-mpg.data"
    z <- tempfile()
    download.file(url,z,mode="wget")
    file <- read.csv(z, sep = '\t')
    print(file)

    This page titled 11.2.5: How to Incorporate Data Files in Your Code Blocks- For R was last modified on Mon, 22 Jul 2024 03:45:45 GMT and is shared under a CC BY-SA 4.0 license and was authored, remixed, and/or curated by LibreTexts.