Showing posts with label R lesson. Show all posts
Showing posts with label R lesson. Show all posts

August 31, 2026

R programming lesson #2: merging pdf files

Use R package "pdftools" to merge separate pdf into one pdf file. You will never need to use sketchy websites or pay for software to do this ever again! It's free and easy with R package pdftools.

August 17, 2026

R programming lesson #3: merging datasets (RNA-seq and Human Protein Atlas example)

Lesson goal: take your dataset and add columns from another dataset. You will add columns by matching shared values between the two datasets (usually columns with gene names, Ensembl Gene IDs, or other accession numbers).

Download the following files to folder "data":

  1. "Additional File 2: Table S1" Excel file from Gonzalez et al. "Sex differences in the late first trimester human placenta transcriptome", Biology of Sex Differences (2018). It is under section "Additional files". 
  2. "proteinatlas.tsv.zip" from The Human Protein Atlas downloadable data page. 
  3. Save the Human Protein Atlas page as a pdf (e.g. print to pdf from Chrome browser) or manually record the database version that you are using. It is good practice to document the database version you are using for later citation and methods sections.


Save the files to a data folder that you can access through R Studio. 

August 24, 2022

R programming lesson #1: load data, subset, and write to a new file

See also: "How to get started with R programming"

Purpose: 

Learn to prepare an Excel spreadsheet for data import, re-save as a .csv file, load into R, look at the data, subset to significant genes, and write the smaller spreadsheet to a new .csv file.

January 31, 2019

R programming lesson #0: How to get started

R is a programming language popular for statistics and bioinformatics.

Table of Contents

Installation

  • Install R, the free behind-the-scenes code that allows your computer to run R scripts
  • Install RStudio, the user interface software
    • Get free RStudio Desktop ("RStudio IDE" open source section). Install this after you install R (not before).
    • Ignore the RStudio Desktop Pro, RStudio Server, or commercial versions. You don't need those.
    • Default settings are ok
    • RStudio is semi-optional. If you are a programming beginner, you do need it. If you have a programming background and know how to run terminal commands, you don't really need it but it's still a nice user interface. 
  • Once you have both installed, open RStudio and it should automatically detect your version of R language (see red arrow). It will also show your default working directory (see orange arrow).

RStudio window showing R version 4.5.3 and working directory C drive
RStudio window showing R version 4.5.3 and working directory C:/

 

Simple practice

  • Open RStudio and try replicating the console commands below. Note that integer lists are written as beginning:ending separated by a colon (e.g. 1:10 means 1,2,3,4,5,6,7,8,9,10).
  • To assign values to variables, R allows either an equal sign or an arrow:
    • x <- 1:10
    • x = 1:10
    • These two things both assign an integer list of 1 to 10 to the variable x.
  • Once you have assigned the values to x, you can now create a new variable y which uses the values of x.
    • y <- x^2
    • This creates variable y with a list of values 1,4,9,16,25,36,49,64,81,100.
  • With two number variables of equal length like our example x and y above, you can create a scatter plot.
    • plot(x,y)
  • The plot function also allows some customization such as selecting the point colors.
    • plot(x,y,col="red")
    • Note that "red" must be in quotes because it is a value, not a variable. You are assigning the value "red" to the function's variable col. This would also work:
    • mycolor = "blue"
    • plot(x,y,col=mycolor)
    • In this case you don't need the quotes since you are passing the value of variable mycolor to variable col. That value is "blue", which R understands as one its named colors.
  • You can also print values to the console using either the variable name or the print() function.
    •  x
    • print(x)
    • print("Hello world!") 
  • If your variable values contain strings (meaning text values), then you can also combine text values with function cat() using commas to separate each string value.
    • mycolor="blue"
    • cat("The value of the variable mycolor is: ", mycolor)  




R programming lesson #2: merging pdf files

Use R package "pdftools" to merge separate pdf into one pdf file. You will never need to use sketchy websites or pay for software ...