Repository navigation
Expand file tree
/
Copy pathEnvironment.R
More file actions
93 lines (71 loc) · 2.29 KB
/
Copy pathEnvironment.R
File metadata and controls
93 lines (71 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#environment :
#It is virtaul space where all the object are stored
#default evnir R_GlobalEnv
#some R Commands for environment
environment() #returns current environment
#list objects
ls()
objects()
#create new Environment
demo <- new.env()
#assign object to the environment
assign("b",c(10, 20 , 30) , envir = demo)
#check that object e3xists
exists("b" , envir = demo)
#access that object
get("b" , envir = demo)
demo$b
#remove object
rm(length , length1)
rm("b" , envir =demo)
#save & load objects
#There are different functions/methods to save objects on the file or disk
#1.save() :
#it is built_in function in r
#it create .RData file , in which we can store all the objects in this files
#later we can load that file using load() function
#syntax :
save(obj1 , obj2 , file = "filePath")
#example :
save(v8 , v9 , file = "objects.RData")
View("objects.RData")
#load() : it is used to load objects from file to R environment
#it is built-in function in R
#syntax :
load(file = "filePath" , envir = environmentName)
#example :
load(file = "objects.Rdata" )
ls(demo)
#save.image() :
#it is an extension of save()
#it also create .RData file but in which we can only sotre current workspace files
#it is buil-in function in R
#save.image()
save.image(file = "filePath.RData")
#example :
save.image(file = "envir.RData")
View("envir.RData")
load(file = "envir.RData" , envir = demo)
View(demo)
#saveRDS() :
#it is built_in function in R
#it create .Rds file in which , we can only store one object
#RDS stands for R Data Serialization
#to read saveRDS files we can use readRDS() function
#syntax :
saveRDS(objectName , file = "filePath.Rds")
#syntax :
ReadRDS(file = "filepath.Rds")
#example:
saveRDS(x , file = "x.Rds")
rm(x)
x <- readRDS("x.Rds")
x
#working directory in R : it is default path in computer system to store objects and other variables
#when we import dataset then it is assumed that the data is present in working directory
#we have a signle working directory also called as current working directory
#command for working directory :
getwd() #returns current working directory
setwd() #it is used to set new working directory or change existing one
#syntax :
setwd(dir = "path")