

{"id":4396,"date":"2017-10-03T11:25:05","date_gmt":"2017-10-03T11:25:05","guid":{"rendered":"http:\/\/data-flair.training\/blogs\/?p=4396"},"modified":"2021-08-25T17:26:45","modified_gmt":"2021-08-25T11:56:45","slug":"object-oriented-programming-in-r","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/object-oriented-programming-in-r\/","title":{"rendered":"Object Oriented Programming (OOP) in R | Create R Objects &amp; Classes"},"content":{"rendered":"<p>In this R tutorial, we are going to discuss one of the most important concepts i.e. Object Oriented Programming in R. We will discuss the concept of objects and classes in R language, the process to create S3 and S4 classes, inheritance in these classes and its methods in the R programming language.<\/p>\n<h2>What is Object Oriented Programming in R?<\/h2>\n<p><strong>Object Oriented Programming (OOP)<\/strong> is a popular programming language. Using its concepts, we can construct the modular pieces of code that can be used to build blocks for large systems. R is a functional language. The support also exists for programming in an OOP style. Object Oriented Programming in R is a superb tool to manage complexity in larger programs. It particularly suits for GUI development.<\/p>\n<p>S3 and S4 are the two important systems in Object Oriented Programming:<\/p>\n<ul>\n<li>S3 is used to overload any function. Therefore, we can call different names of the function. And, it depends upon the type of input parameter or the number of a parameter.<\/li>\n<li>An important characteristic of OOP is S4. However, it poses a limitation as it is quite tricky to debug. An alternate for the S4 is the reference class.<\/li>\n<\/ul>\n<p><em><strong>Understand the <a href=\"https:\/\/data-flair.training\/blogs\/r-function\/\">R Programming Functions<\/a>\u00a0thoroughly<\/strong><\/em><\/p>\n<h3>What are Objects and Classes in R?<\/h3>\n<ul>\n<li>Programmers\u00a0can perform\u00a0OOP programming in R. That is, everything in <a href=\"https:\/\/en.wikipedia.org\/wiki\/R_(programming_language)\">R<\/a> is an object.<\/li>\n<li>An object is a data structure. It has some methods that can act upon its attributes.<\/li>\n<li>Classes\u00a0are used\u00a0as an outline or design for the object. It encapsulates the data members along with the functions.<\/li>\n<\/ul>\n<h4>Classes in R<\/h4>\n<h5>1. S3 Class<\/h5>\n<p>With the help of the S3 class, you can avail its ability to implement generic function OO. Also, using only the first argument, S3\u00a0is able to dispatch. S3 is different from conventional programming languages like Java, C++, and C# that implement message passing OO. This makes S3 easier to implement. In S3 class, the generic function makes the call to the method. S3 is very casual and does not have any formal definition of classes.<\/p>\n<p>S3 requires very less knowledge on the part of the programmer.<\/p>\n<h5>2. S4 Class<\/h5>\n<p>S4 Class is a bit similar to S3 but it is more formal than the latter. It differs from S3 in two different ways. Firstly, in S4, there are formal class definitions that provide description and representation of classes. Furthermore, it has special helper functions for defining methods and generics. S4 also facilitates multiple dispatches. This means that the generic functions are able to pick up methods based on the class comprising of multiple arguments.<\/p>\n<p>Let&#8217;s understand these R classes with the help of examples.<\/p>\n<p><strong>1.1 Creating an S3 class<\/strong><\/p>\n<p>We will show how to define a function that will create and return an object of a given class. A list is created with the relevant members, the list\u2019s class is set, and a copy of the list is being returned.<\/p>\n<p><strong>1.2 Constructing a new S3 class<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">s &lt;- list(name = \"DataFlair\", age = 29, GPA = 4.0)\r\nclass(s) &lt;- \"student\"\r\ns<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/s-list.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-63678\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/s-list.jpg\" alt=\"s list\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/s-list.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/s-list-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/s-list-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/s-list-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/s-list-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/s-list-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p>Let us now define our generic function print.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">print\r\nfunction (x, ...) \r\nUseMethod(\"print\")<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/print-function-UseMethod.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-63679\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/print-function-UseMethod.jpg\" alt=\"print function UseMethod\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/print-function-UseMethod.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/print-function-UseMethod-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/print-function-UseMethod-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/print-function-UseMethod-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/print-function-UseMethod-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/print-function-UseMethod-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p>Now, we will make a generic function &#8211; GPA<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">GPA &lt;- function(obj) {\r\nUseMethod(\"GPA\")\r\n}<\/pre>\n<p>Let us now implement a default method for our GPA function &#8211;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">GPA.default &lt;- function(obj) {\r\ncat(\"This is a generic function\\n\")\r\n}<\/pre>\n<p>Now, we will make a new method for the class \u201cstudent\u201d<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">GPA.student &lt;- function(obj) {\r\ncat(\"Total GPA is\", obj$GPA, \"\\n\")\r\n}<\/pre>\n<p>Now, let us run this method.<\/p>\n<p>GPA(s)<\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/GPA-function-obj-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-63680\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/GPA-function-obj-1.jpg\" alt=\"GPA function obj 1\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/GPA-function-obj-1.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/GPA-function-obj-1-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/GPA-function-obj-1-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/GPA-function-obj-1-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/GPA-function-obj-1-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/GPA-function-obj-1-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><em><strong>Wait! Have you checked the\u00a0<a href=\"https:\/\/data-flair.training\/blogs\/r-vector-functions\/\">R Vector Functions<\/a><\/strong><\/em><\/p>\n<p><strong>1.3 Inheritance in S3<\/strong><\/p>\n<p>In S3, inheritance is achieved by\u00a0applying the class attribute in a vector.<\/p>\n<p><strong>For example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; fit &lt;- glm(rpois(100, lambda = 1) ~\r\n+ 1, family = \"poisson\")\r\n&gt; class(fit)\r\n&gt; methods(\"residuals\")\r\n&gt; methods(\"model.matrix\")[\/php]\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/fit-glm.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-63681\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/fit-glm.jpg\" alt=\"fit glm\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/fit-glm.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/fit-glm-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/fit-glm-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/fit-glm-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/fit-glm-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/fit-glm-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p>If no method is found for the first class, the second class is checked.<\/p>\n<p><strong>1.4 Useful S3 method functions<\/strong><\/p>\n<ul>\n<li>getS3method(&#8220;print&#8221;,&#8221;person&#8221;)<\/li>\n<li>getAnywhere<\/li>\n<\/ul>\n<p>S3 gets the appropriate method associated with a class and it is useful to see how a method is implemented.<\/p>\n<p>Sometimes, methods are non-visible, because they are hidden in a namespace. We use getS3method or getAnywhere to resolve this issue.<\/p>\n<p><strong>getS3method:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">require(stats)\r\nexists(\"predict.ppr\") # False\r\ngetS3method(\"predict\", \"ppr\") #DataFlair<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/require-stats.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-63684\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/require-stats.jpg\" alt=\"require stats\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/require-stats.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/require-stats-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/require-stats-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/require-stats-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/require-stats-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/require-stats-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>getAnywhere:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">getAnywhere(\u201csimpleloess\u201d)<\/pre>\n<p><em><strong>You must know the <a href=\"https:\/\/data-flair.training\/blogs\/principal-components-and-factor-analysis-in-r\/\">Principal Components and Factor Analysis in R<\/a><\/strong><\/em><\/p>\n<h5>S4 Class<\/h5>\n<p><strong>2.1 Creating an S4 class<\/strong><\/p>\n<p>We use setClass() command to create\u00a0S4\u00a0class. We specify a function to verify that the data is consistent (validation) and also specify the default values (the prototype).<\/p>\n<p><strong>2.2 Constructing a new S4 class<\/strong><\/p>\n<p>We have to define the class and its slots, and the code to define the class is as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">Agent &lt;- setClass(\r\n\u00a0# Set the name for the class\r\n\u00a0\"Agent\",\r\n\r\n\u00a0# Define the slots\r\n\u00a0slots = c(\r\n\u00a0\u00a0\u00a0location = \"numeric\",\r\n\u00a0\u00a0\u00a0velocity \u00a0\u00a0= \"numeric\",\r\n\u00a0\u00a0\u00a0active \u00a0\u00a0= \"logical\"\r\n\u00a0),\r\n\r\n\u00a0# Set the default values for the slots. (optional)\r\n\u00a0prototype=list(\r\n\u00a0\u00a0\u00a0location = c(0.0,0.0),\r\n\u00a0\u00a0\u00a0active \u00a0\u00a0= TRUE,\r\n\u00a0\u00a0\u00a0velocity = c(0.0,0.0)\r\n\u00a0),\r\n\r\n\u00a0# Make a function that can test to see if the data is consistent.\r\n\u00a0# This is not called if you have an initialize function defined!\r\n\u00a0validity=function(object)\r\n\u00a0{\r\n\u00a0\u00a0\u00a0if(sum(object@velocity^2)&gt;100.0) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0return(\"The velocity level is out of bounds.\")\r\n\u00a0\u00a0\u00a0}\r\n\u00a0\u00a0\u00a0return(TRUE)\r\n\u00a0}\r\n)\r\n\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/Agent-setClass-output.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-63687\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/Agent-setClass-output.jpg\" alt=\"Agent setClass output\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/Agent-setClass-output.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/Agent-setClass-output-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/Agent-setClass-output-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/Agent-setClass-output-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/Agent-setClass-output-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/Agent-setClass-output-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p>We can create an object whose class is Agent, as the code to define the class is as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">a &lt;- Agent()\r\n&gt; a<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/a-Agent.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-63690\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/a-Agent.jpg\" alt=\"a Agent\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/a-Agent.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/a-Agent-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/a-Agent-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/a-Agent-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/a-Agent-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/a-Agent-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p>We can obtain details about the elements using the SlotNames command as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">is.object(a)\r\n&gt; isS4(a)\r\n&gt; slotNames(a)\r\n&gt; slotNames(\"Agent\")<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/is.object-a.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-63695\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/is.object-a.jpg\" alt=\"is.object a - Object Oriented Programming in R\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/is.object-a.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/is.object-a-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/is.object-a-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/is.object-a-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/is.object-a-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/is.object-a-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p>There are two functions<strong> <em>is.object<\/em><\/strong> and the <strong><em>isS4<\/em><\/strong> commands.<\/p>\n<ul>\n<li>We use is.object command to determine whether a variable refers to an object or not.<\/li>\n<li>We use the isS4 command to determine whether a variable is an S4 object or not.<\/li>\n<li>The importance of the commands is that the <em>isS4<\/em> command alone cannot determine that a variable is an S3 object. First, we need to determine whether the variable is an object and then decide if it is S4 or not.<\/li>\n<\/ul>\n<p>In an object, we use a set of commands to get information about the data elements, or slots within an object. The first is the <strong>slotNames<\/strong> command which can take either an object or the name of a class. We obtain names of slots that are related to the class as strings.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; slotNames(a)\r\n&gt; slotNames(\"Agent\")<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/slotNames-a.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-63709\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/slotNames-a.jpg\" alt=\"slotNames a - Object Oriented Programming in R\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/slotNames-a.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/slotNames-a-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/slotNames-a-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/slotNames-a-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/slotNames-a-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/slotNames-a-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><em><strong>Do you know about <a href=\"https:\/\/data-flair.training\/blogs\/r-string-manipulation\/\">R String Manipulation Functions<\/a><\/strong><\/em><\/p>\n<p>The <strong>getSlots<\/strong> and <strong>slotNames<\/strong> command are similar as they both take the name of a class as a string. We obtain a vector in return whose entries consist of the types associated with slots. The names of the entries are the names of the slots.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; getSlots(\"Agent\")\r\nlocation\u00a0 velocity\u00a0\u00a0\u00a0 active\r\n\"numeric\" \"numeric\" \"logical\"\r\n&gt; s &lt;- getSlots(\"Agent\")\r\n&gt; s[1]\r\nlocation\r\n\"numeric\"\r\n&gt; s[[1]]\r\n&gt; names(s)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/getSlots-agent.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-58975\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/getSlots-agent.jpg\" alt=\"getSlots agent\" width=\"1366\" height=\"728\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/getSlots-agent.jpg 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/getSlots-agent-150x80.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/getSlots-agent-300x160.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/getSlots-agent-768x409.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/getSlots-agent-1024x546.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/getSlots-agent-520x277.jpg 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<p>The next command which we will examine is the <strong>getClass<\/strong> command. It has two forms. If you assign S4 class as a variable it returns a list of slots for the class associated with the variable. Another, if you assign a character string with the name of a class it gives the slots and their data types.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; getClass(a)\r\nAn object of class \"Agent\"\r\nSlot \"location\":\r\nSlot \"velocity\":\r\nSlot \"active\":\r\n&gt; getClass(\"Agent\")\r\nClass \"Agent\" [in \".GlobalEnv\"]\r\nSlots:\r\nName:\u00a0 location velocity\u00a0\u00a0 active\r\nClass:\u00a0 numeric\u00a0 numeric\u00a0 logical<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/getClass-a.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-63692\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/getClass-a.jpg\" alt=\"getClass a\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/getClass-a.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/getClass-a-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/getClass-a-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/getClass-a-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/getClass-a-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/getClass-a-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p>The final command for examining is the <strong>slot<\/strong> command. In an object to set the value of slot, we can use slot command. \u201c@\u201d operator is used at the place of slot command.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">slot(a,\"location\")\r\n&gt; slot(a,\"location\") &lt;- c(1,5)\r\n&gt; a<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/slot-a-location-2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-63694\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/slot-a-location-2.jpg\" alt=\"slot a location\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/slot-a-location-2.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/slot-a-location-2-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/slot-a-location-2-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/slot-a-location-2-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/slot-a-location-2-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/slot-a-location-2-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<h2>Summary<\/h2>\n<p>Classes and objects are the most important concepts of Object Oriented Programming language(OOP). We tried to describe the Object Oriented Programming in R in great detail.<\/p>\n<p><em><strong>The secret to crack your R Interview &#8211; <a href=\"https:\/\/data-flair.training\/blogs\/r-interview-questions-and-answers\/\">R Programming Interview Questions<\/a><\/strong><\/em><\/p>\n<p>If in case you have any questions, feel free to share with us. We will be glad to solve your queries.<span hidden class=\"__iawmlf-post-loop-links\" data-iawmlf-links=\"[{&quot;id&quot;:1467,&quot;href&quot;:&quot;https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/R_(programming_language)&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20251001042859\\\/https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/R_(programming_language)&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-09 08:17:04&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-12 12:22:33&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-15 12:29:21&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-18 15:20:53&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-21 18:00:25&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-25 04:08:57&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-28 06:54:42&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-31 09:47:17&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-03 17:14:22&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-06 19:17:34&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-09 21:09:32&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-13 04:31:41&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-16 15:06:53&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-19 19:03:58&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-23 05:30:29&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-26 10:18:28&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-29 11:45:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-01 12:00:34&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-04 12:09:55&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-07 15:09:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-10 18:01:34&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-13 23:45:59&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-17 05:29:44&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-20 07:23:59&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-23 10:05:24&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-26 14:54:33&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-01 16:00:29&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-04 19:56:49&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-08 03:19:57&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-03-11 07:47:37&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-14 13:54:22&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-17 17:24:09&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-03-20 23:04:55&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-24 00:07:34&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-27 00:15:51&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-30 08:20:38&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-03 14:48:26&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-06 19:55:35&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-10 05:52:27&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-13 07:47:26&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-16 08:05:10&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-19 13:04:23&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-22 13:52:44&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-25 13:58:03&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-29 01:16:25&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-02 04:13:02&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-05 06:33:38&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-08 17:48:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-12 03:38:06&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-15 04:53:06&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-18 09:15:30&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-21 12:35:48&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-25 03:51:04&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-28 07:13:15&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-01 04:45:49&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-04 06:40:14&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-07 06:45:43&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-10 09:02:48&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-13 16:18:42&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-13 16:18:42&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this R tutorial, we are going to discuss one of the most important concepts i.e. Object Oriented Programming in R. We will discuss the concept of objects and classes in R language, the&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":58985,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[9261,11235,20102],"class_list":["post-4396","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-r","tag-oop-in-r","tag-r-object-oriented-programming","tag-r-objects-and-classes"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Object Oriented Programming (OOP) in R | Create R Objects &amp; Classes - DataFlair<\/title>\n<meta name=\"description\" content=\"Object oriented programming in R covers objects and classes; S3 class and S4 class, its creation, inheritance and method functions. OOP in R is a superb tool to manage complexity in larger programs.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/object-oriented-programming-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Object Oriented Programming (OOP) in R | Create R Objects &amp; Classes - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Object oriented programming in R covers objects and classes; S3 class and S4 class, its creation, inheritance and method functions. OOP in R is a superb tool to manage complexity in larger programs.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/object-oriented-programming-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2017-10-03T11:25:05+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-25T11:56:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/Object-Oriented-Programming-in-R-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Object Oriented Programming (OOP) in R | Create R Objects &amp; Classes - DataFlair","description":"Object oriented programming in R covers objects and classes; S3 class and S4 class, its creation, inheritance and method functions. OOP in R is a superb tool to manage complexity in larger programs.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/object-oriented-programming-in-r\/","og_locale":"en_US","og_type":"article","og_title":"Object Oriented Programming (OOP) in R | Create R Objects &amp; Classes - DataFlair","og_description":"Object oriented programming in R covers objects and classes; S3 class and S4 class, its creation, inheritance and method functions. OOP in R is a superb tool to manage complexity in larger programs.","og_url":"https:\/\/data-flair.training\/blogs\/object-oriented-programming-in-r\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2017-10-03T11:25:05+00:00","article_modified_time":"2021-08-25T11:56:45+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/Object-Oriented-Programming-in-R-1.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/object-oriented-programming-in-r\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/object-oriented-programming-in-r\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"Object Oriented Programming (OOP) in R | Create R Objects &amp; Classes","datePublished":"2017-10-03T11:25:05+00:00","dateModified":"2021-08-25T11:56:45+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/object-oriented-programming-in-r\/"},"wordCount":1096,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/object-oriented-programming-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/Object-Oriented-Programming-in-R-1.jpg","keywords":["OOP in R","R Object oriented Programming","R Objects and Classes"],"articleSection":["R Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/object-oriented-programming-in-r\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/object-oriented-programming-in-r\/","url":"https:\/\/data-flair.training\/blogs\/object-oriented-programming-in-r\/","name":"Object Oriented Programming (OOP) in R | Create R Objects &amp; Classes - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/object-oriented-programming-in-r\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/object-oriented-programming-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/Object-Oriented-Programming-in-R-1.jpg","datePublished":"2017-10-03T11:25:05+00:00","dateModified":"2021-08-25T11:56:45+00:00","description":"Object oriented programming in R covers objects and classes; S3 class and S4 class, its creation, inheritance and method functions. OOP in R is a superb tool to manage complexity in larger programs.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/object-oriented-programming-in-r\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/object-oriented-programming-in-r\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/object-oriented-programming-in-r\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/Object-Oriented-Programming-in-R-1.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/10\/Object-Oriented-Programming-in-R-1.jpg","width":802,"height":420,"caption":"Object Oriented Programming in R"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/object-oriented-programming-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"R Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/r\/"},{"@type":"ListItem","position":3,"name":"Object Oriented Programming (OOP) in R | Create R Objects &amp; Classes"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team provides industry-driven content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our expert educators focus on delivering value-packed, easy-to-follow resources for tech enthusiasts and professionals.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam2\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/4396","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=4396"}],"version-history":[{"count":16,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/4396\/revisions"}],"predecessor-version":[{"id":63710,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/4396\/revisions\/63710"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/58985"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=4396"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=4396"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=4396"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}