find the size of a file in r

To find the size of a file in R, you can use the file.info() function to get information about the file, including its size. Then, you can access the size element of the resulting list. Here's an example:

main.r
# set the path to your file here
file_path <- "path/to/your/file"

# get info about the file
file_info <- file.info(file_path)

# get the file size in bytes
file_size <- file_info$size

# print the file size
print(file_size)
225 chars
12 lines

Alternatively, if you only want to know the file size and don't actually need to read the file into R, you can use the readBin() function with an empty what argument to read 0 bytes from the file and return its size. Here's an example:

main.r
# set the path to your file here
file_path <- "path/to/your/file"

# get the file size in bytes
file_size <- file.info(file_path)$size

# get the file size by reading 0 bytes from it
file_size2 <- length(readBin(file_path, what="", n=0))

# print the file sizes
print(file_size)
print(file_size2)
297 chars
13 lines

gistlibby LogSnag