Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the method of operating files in R language?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report