Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the method of operating files in R language?

Shulou Source: shulou.com Published: 2022-06-02 17:33:53 09月14日 Update

This article mainly introduces "what is the method of operating files in R language". In the daily operation, I believe that many people have doubts about the methods of operating files in R language. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "what is the method of operating files in R language?" Next, please follow the editor to study!

The structure of our test directory for the whole article is as follows (generate a directory structure tree, you can open a command line window directly under the current path, type: tree / f or tree / F):

Blog │ file1.txt │ file2.txt │ file3.txt │ file4.tar.gz │ ├─ dir1 │ file1.txt │ file2.txt │ └─ dir2 file1.tar.gz

1. Reading the list of files and folders

Before doing this, we first use getwd () to view the default file path, and then use setwd (path0) to modify the file default path, path0 is the set path, in this case, set to the Blog folder.

Get all files under the current path: list.files ()

Get all folders under the current path: list.dirs ()

We can see the difference between the two through the following picture. Usually represents the current path:

What do we need to do if we want to get all the files under all the folders?

In fact, it is very simple. You only need to change the recursive = TRUE in list.files (), as shown below:

two。 Create new files and folders

Create a new file: file.create ()

Create a new folder: dir.create ()

3. Deletion of files and folders

Delete file: file.remove ()

Delete folder: dir.remove ()

4. Check whether files and folders exist

Check to see if the file exists: file.exists ()

Check whether the folder exists: dir.exists ()

At this point, the study of "what is the method of operating files in R language" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Files folders paths methods languages learning more directories articles help practical next the following figure representatives examples commands articles tree construction theory knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Tech Info Huawei Shulou Information NVidia