Open In App

How to set HTML meta elements with knitr ?

Last Updated : 06 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Sometimes you might want to generate some R code, or any other code without wrapping it up in a <code> tag, or maybe you want to specify some elements without the specific elements. Well, the thing you need at the moment is setting up the meta elements using knitr.

Metadata means information about data. The <meta> tag in HTML provides information about HTML Document or in simple words, it provides important information about a document. These tags are basically used to add name/value pairs to describe properties of HTML documents, such as expiry date, author name, list of keywords, document author, etc. A web document can include one or more meta tags depending on information, but in general, it doesn’t affect the physical appearance of the document. 

Syntax:

<meta name="meta-name-here"<!—the knitr method—>

Example 1: In this example, we will show the document information through Metadata.

HTML




<!DOCTYPE html>
<html>
<head>
    <meta name="author" content=
          "<!--rinline I(Sys.getenv('GeeksforGeeks')) -->">
    <meta name="date" content=
          "<!--rinline I(as.character(Sys.time())) -->">
</head>
  
<body></body>
</html>


Example 2: In this example, we are using <meta> tag.

HTML




<!DOCTYPE html> 
<html
<head>
    <!--begin.rcode results='asis', echo=TRUE
    cat('
      <meta name="author" content="', 
            Sys.getenv('GeeksforGeeks'), '"> 
  
      <meta name="date" content="', 
            as.character(Sys.time()),'-->">
    ',sep="")
    end.rcode-->
</head>
</html>


Note: Both examples do not contain a body section or any displaying HTML elements, so they will not display any output result.



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads