# How to implement Limma package in R snippet on Knime

**URL:** <https://forum.knime.com/t/how-to-implement-limma-package-in-r-snippet-on-knime/77036>\
**Category:** KNIME Analytics Platform\
**Created:** [February 4, 2024, 10:46am UTC](https://forum.knime.com/t/how-to-implement-limma-package-in-r-snippet-on-knime/77036 "2024-02-04T10:46:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erzascarlet](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/e/839c29/32.png) [@Erzascarlet](https://forum.knime.com/u/Erzascarlet)\
**Post date:** [February 4, 2024, 10:46am UTC](https://forum.knime.com/t/how-to-implement-limma-package-in-r-snippet-on-knime/77036/1 "2024-02-04T10:46:04Z")

</div>

Hello, I am working with a gene expression dataset. In the image below, you can see the structure of my dataset. I am attempting to straightforwardly use the Limma package on my dataset. I am using a CSV reader to read my file, and then I am using an R snippet with the following code to run the Limma package. However, I am encountering different errors, with the error below being the most persistent. Should I be performing more data transformation steps before feeding my data into the R snippet with the limma package? If someone could tell me where I am making a mistake and how I can fix it, it would be great. Or if someone already has an existing limma node for knime for Windows that would be great as well.

code  
"

# Convert the ‘class’ column to a factor

kIn$class ← factor(kIn$class)

# Create a design matrix

design ← model.matrix(~0 + kIn$class)

# Extract the expression data

exprs\_data ← as.matrix(kIn[, -1]) # Convert to a matrix

# Load the limma package

if (!requireNamespace(“BiocManager”, quietly = TRUE))  
install.packages(“BiocManager”)  
BiocManager::install(“limma”)  
library(limma)

# Fit the linear model

fit ← lmFit(exprs\_data, design)

# Apply empirical Bayes moderation

fit ← eBayes(fit)

# Extract the results

results ← topTable(fit, coef=“kIn$classpos”, number=nrow(exprs\_data))"

This is the error

“ERROR R Snippet 5:489 Execute failed: Failed to evaluate the script:  
Error : Error in lmFit(exprs\_data, design) :  
row dimension of design doesn’t match column dimension of data object”

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/a/7/a76512008749c9c95e91477ab4f667733a8c0b2f.png)

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [February 4, 2024, 11:29am UTC](https://forum.knime.com/t/how-to-implement-limma-package-in-r-snippet-on-knime/77036/2 "2024-02-04T11:29:10Z")

</div>

@Erzascarlet welcome to the KNIME forum. Maybe you could provide us with a complete readable code and example:

> [@Dynamic Filter connected to several Python Views of a dashboard](https://forum.knime.com/t/dynamic-filter-connected-to-several-python-views-of-a-dashboard/75456/8):
>
> @DanGenEire what would be good is a complete workflow example and a code that is formatted in a readable way or add it as a file. [image] import pandas as pd import numpy as np I will see if I can come up with an example later.

First you might want to check how to bring data to and from an R node.

[https://docs.knime.com/latest/r\_installation\_guide/index.html#\_introduction](https://docs.knime.com/latest/r_installation_guide/index.html#_introduction)

```auto
df <- knime.in
knime.out <- as.data.table(df)

```

> [@splitting strings into letters using R snippet node](https://forum.knime.com/t/splitting-strings-into-letters-using-r-snippet-node/76340/11):
>
> @0nly4phil for the second example as.data.table() as well as a conversion to character seems to do the trick. The transfer is done with “data.table”: df1 \<- knime.in df1 \<- as.data.frame(df1) a \<- as.character(df1$'Column Header') a \<- strsplit(a,split="") b \<-matrix(unlist(a),ncol=10,byrow=T) df1$'splt'\<-b knime.out \<- as.data.table(df1) [Convert data from KNIME to R and back with split of text column - KNIME Forum (76340).knwf](https://forum.knime.com/uploads/short-url/nOaMYRtufyKAp8md6yzAWMHMH90.knwf) (88.8 KB)

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [May 4, 2024, 11:29am UTC](https://forum.knime.com/t/how-to-implement-limma-package-in-r-snippet-on-knime/77036/3 "2024-05-04T11:29:48Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
