In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what are the methods of operating R language file directories?". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The basic operation method of R language to directory and file
1. Work path
Getwd () lists the current work path
Setwd (dir) sets the work path, and the parameter dir is the path to be set.
2. List the files in the directory
The function list.files is exactly the same as dir, which lists all files (including directories) under the path; the function list.dirs lists only all directories under the path.
List.files (path = ".", pattern = NULL, all.files = FALSE, full.names = FALSE, recursive = FALSE, ignore.case = FALSE, include.dirs = FALSE, no..) = FALSE) dir (path = ".", pattern = NULL, all.files = FALSE, full.names = FALSE, recursive = FALSE, ignore.case = FALSE, include.dirs = FALSE,no.. = FALSE) list.dirs (path = ".", full.names = TRUE, recursive = TRUE)
Parameters:
Path path. If left empty, it defaults to the current working path, that is, the path obtained by getwd ()
Pattern regular expression. If pattern is not NULL, the file (directory) whose name satisfies the regular expression is returned.
All.files does not show hidden files (directories) if FALSE, and returns all files (directories) if TRUE.
Full.names returns only the file (directory) name if FALSE, and the file (directory) path if TRUE.
If recursive is FALSE, only the child files (directories) of the path will be returned. If TRUE, all child and grandchildren files (directories) will be returned.
If ignore.case is TRUE, it is not case sensitive when matching pattern.
When recursive is TURE, that is, all children and grandchildren files are displayed in include.dirs, if include.dirs is FALSE, only the final file name is listed, but not the directory name at the intermediate level
No.. If TRUE, it does not display "." And "..".
3. Create a new directory
Dir.create is used to create a new directory
Dir.create (path, showWarnings = TRUE, recursive = FALSE,mode = "0777")
The default recursive of the function is FALSE, that is, only the first-level subdirectories in path are created, and when recursive is TRUE, you can create new multi-level subdirectories.
It is worth noting that when a directory already exists, a new directory will not overwrite the previous directory. If showWarnings is TRUE, it will be reminded that the directory already exists, but not if it is FALSE.
In addition, the parameter mode is a Unix-alike parameter.
4. Copy
File.copy is used to copy files
File.copy (from, to, overwrite = recursive, recursive = FALSE,copy.mode = TRUE, copy.date = FALSE)
From is the original file (directory) name, to is the new file (directory) name, both can be vector, but the length must be the same
If overwrite is TRUE, the file is overwritten
Recursive must be TRUE when recursive replicates a directory
If copy.mode is TRUE,permission bits, copy it together.
If copy.date is TRUE, the file date will be copied as well.
5. Delete
The function unlink can be used to delete files or directories, and the function file.remove can be used to delete files.
Unlink (x, recursive = FALSE, force = FALSE)
X is the file or directory to be deleted, which can be vector (that is, batch deletion). When deleting a directory, recursive should be TRUE, which means that the files in the directory are also deleted.
6. Rename
File.rename for renaming
File.rename (from, to)
From is the original file (directory) name, to is the new file (directory) name, both can be vector, but the length must be the same.
7. Check whether the file exists
Dir.exists (paths) file.exists (paths)
The parameter paths can be vector, that is, you can check the existence of files (directories) in batch.
This is the end of the content of "what are the methods of operating the R language file directory?" Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.