1

I was wondering what is the correct way to get the C/C++ source code of any secondary(to distinguish from the Primitive/Internal ones) function in R. Related questions are here, here, here and here:

Mine is different so that I used "secondary" in my question. For example, the read.table() function, within R console I got:

>?read.table

read.table                package:utils                R Documentation

Data Input

Description:

     Reads a file in table format and creates a data frame from it,
     with cases corresponding to lines and variables to fields in the
     file.

Usage:
     read.table(file, header = FALSE, sep = "", quote = "\"'",
        ......

Or

> getAnywhere(read.table)
A single object matching ‘read.table’ was found
It was found in the following places
  package:utils
  namespace:utils
with value

function (file, header = FALSE, sep = "", quote = "\"'", dec = ".", 

     ......

    attr(data, "row.names") <- row.names
    data
}
<bytecode: 0x560ff88edd40>
<environment: namespace:utils>

Search the website I got:

https://svn.r-project.org/R/trunk/src/library/utils/src/utils.c

https://svn.r-project.org/R/trunk/src/library/utils/src/utils.h

How to get the C/C++ source code of the read.table function instead of R code, if this is reasonable?

Yifangt
  • 151
  • 1
  • 10

1 Answers1

5

The searchable R source code at https://github.com/wch/r-source is really useful for this:

So here you are: The underlying C implementation for read.table can be found in src/main/scan.c, starting with the function do_scan.

Ralf Stubner
  • 26,263
  • 3
  • 40
  • 75